/* ============================================
   RIICHI~SENSEI — Master Stylesheet
   Monochrome Japanese Academy Design
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Noto+Serif+JP:wght@400;700;900&family=Noto+Sans+JP:wght@300;400;500;700&family=Source+Code+Pro:wght@400;600&display=swap');

/* --- OpenDyslexic Font --- */
@font-face {
  font-family: 'OpenDyslexic';
  src: url('../fonts/OpenDyslexic-Regular.otf') format('opentype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'OpenDyslexic';
  src: url('../fonts/OpenDyslexic-Bold.otf') format('opentype');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'OpenDyslexic';
  src: url('../fonts/OpenDyslexic-Italic.otf') format('opentype');
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: 'OpenDyslexic';
  src: url('../fonts/OpenDyslexic-BoldItalic.otf') format('opentype');
  font-weight: 700;
  font-style: italic;
  font-display: swap;
}

/* --- CSS Variables --- */
:root {
  --black: #000000;
  --near-black: #111111;
  --dark-gray: #222222;
  --medium-gray: #555555;
  --gray: #888888;
  --light-gray: #cccccc;
  --near-white: #f0f0f0;
  --white: #ffffff;
  --border: #333333;
  --border-light: #dddddd;

  --font-heading: 'Noto Serif JP', 'Georgia', serif;
  --font-body: 'Noto Sans JP', 'Helvetica Neue', sans-serif;
  --font-mono: 'Source Code Pro', monospace;

  --max-width: 1500px;
  --sidebar-width: 260px;
  --content-width: 1140px;
}

/* --- Dark Mode Variables --- */
body.dark-mode {
  --black: #e8e8e8;
  --near-black: #d8d8d8;
  --dark-gray: #c0c0c0;
  --medium-gray: #a0a0a0;
  --gray: #777777;
  --light-gray: #444444;
  --near-white: #1e1e1e;
  --white: #141414;
  --border: #555555;
  --border-light: #333333;
}
body.dark-mode {
  background: #141414;
  color: #d8d8d8;
}
body.dark-mode .site-header {
  background: #0a0a0a;
  border-bottom-color: #444;
}
body.dark-mode .site-logo,
body.dark-mode .site-logo:visited {
  color: #e0e0e0;
}
body.dark-mode .header-nav a,
body.dark-mode .header-nav a:visited {
  color: #999;
}
body.dark-mode .header-nav a:hover {
  color: #e0e0e0;
  border-bottom-color: #e0e0e0;
}
body.dark-mode .sidebar {
  background: #1a1a1a;
  border-right-color: #333;
}
body.dark-mode .sidebar a,
body.dark-mode .sidebar a:visited {
  color: #c0c0c0;
}
body.dark-mode .sidebar a:hover {
  background: #222;
  border-left-color: #e0e0e0;
}
body.dark-mode .sidebar a.active {
  background: #222;
  border-left-color: #e0e0e0;
  color: #fff;
}
body.dark-mode a { color: #c0c0c0; }
body.dark-mode a:hover { color: #e0e0e0; }
body.dark-mode a:visited { color: #a0a0a0; }
body.dark-mode th {
  background: #2a2a2a;
  color: #e0e0e0;
}
body.dark-mode tr:nth-child(even) {
  background: #1a1a1a;
}
body.dark-mode code {
  background: #1e1e1e;
  border-color: #444;
  color: #d0d0d0;
}
body.dark-mode .info-box,
body.dark-mode .caution-box,
body.dark-mode .quiz-box,
body.dark-mode .rule-variant-box,
body.dark-mode .example-box {
  background: #1a1a1a;
  border-color: #555;
}
body.dark-mode .quiz-options li {
  border-color: #444;
  color: #c0c0c0;
}
body.dark-mode .quiz-options li:hover {
  background: #222;
  border-color: #888;
}
body.dark-mode .quiz-options li.correct {
  background: #1e2a1e;
  border-color: #e0e0e0;
}
body.dark-mode .quiz-options li.incorrect {
  border-color: #555;
  color: #666;
}
body.dark-mode .quiz-btn {
  background: #1a1a1a;
  color: #d0d0d0;
  border-color: #888;
}
body.dark-mode .quiz-btn:hover {
  background: #d0d0d0;
  color: #141414;
}
body.dark-mode .tile-display {
  background: #1a1a1a;
  border-color: #444;
}
body.dark-mode .site-footer {
  background: #0a0a0a;
  border-top-color: #444;
  color: #666;
}
body.dark-mode .topic-card {
  border-color: #444;
}
body.dark-mode .topic-card:hover {
  border-color: #888;
}
body.dark-mode .topic-card .card-title {
  color: #e0e0e0;
}
body.dark-mode .quiz-reveal {
  border-top-color: #888;
}
body.dark-mode blockquote {
  background: #1a1a1a;
  border-left-color: #888;
}
body.dark-mode .page-nav {
  border-top-color: #555;
}
body.dark-mode .flow-step {
  border-color: #888;
  color: #d0d0d0;
  background: #1a1a1a;
}
body.dark-mode .glossary-entry {
  border-bottom-color: #333;
}
body.dark-mode .progress-fill {
  background: #e0e0e0;
}

/* --- Dyslexic Font Mode --- */
body.dyslexic-mode {
  --font-body: 'OpenDyslexic', 'Comic Sans MS', sans-serif;
  --font-heading: 'OpenDyslexic', 'Comic Sans MS', serif;
}
body.dyslexic-mode {
  font-family: var(--font-body);
  line-height: 2;
  letter-spacing: 0.03em;
  word-spacing: 0.12em;
}
body.dyslexic-mode h1,
body.dyslexic-mode h2,
body.dyslexic-mode h3,
body.dyslexic-mode h4,
body.dyslexic-mode h5,
body.dyslexic-mode h6 {
  font-family: var(--font-heading);
  letter-spacing: 0.02em;
}
body.dyslexic-mode p {
  text-align: left;
}
body.dyslexic-mode .sidebar a,
body.dyslexic-mode .header-nav a,
body.dyslexic-mode .quiz-options li,
body.dyslexic-mode td,
body.dyslexic-mode th {
  font-family: var(--font-body);
}
body.dyslexic-mode .tile-label {
  font-family: var(--font-mono);
}

/* --- Accessibility Toggle Buttons --- */
.a11y-toggles {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  margin-left: 0.8rem;
}
.a11y-btn {
  background: transparent;
  color: var(--light-gray);
  border: 1px solid #555;
  border-radius: 3px;
  padding: 0.2rem 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  transition: all 0.15s;
  white-space: nowrap;
  line-height: 1.3;
}
.a11y-btn:hover {
  background: rgba(255,255,255,0.1);
  border-color: #999;
  color: #fff;
}
.a11y-btn.active {
  background: var(--white);
  color: var(--black);
  border-color: var(--white);
}
body.dark-mode .a11y-btn.active {
  background: #e0e0e0;
  color: #141414;
  border-color: #e0e0e0;
}

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-body);
  font-weight: 400;
  line-height: 1.85;
  color: var(--near-black);
  background: var(--white);
  -webkit-font-smoothing: antialiased;
}

/* --- Typography --- */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  font-weight: 700;
  line-height: 1.3;
  color: var(--black);
}

h1 { font-size: 2rem; margin-bottom: 1rem; border-bottom: 3px double var(--black); padding-bottom: 0.5rem; }
h2 { font-size: 1.5rem; margin: 2.5rem 0 1rem; border-bottom: 1px solid var(--border); padding-bottom: 0.4rem; }
h3 { font-size: 1.2rem; margin: 2rem 0 0.8rem; }
h4 { font-size: 1.05rem; margin: 1.5rem 0 0.5rem; }

p { margin-bottom: 1rem; text-align: justify; }

a { color: var(--near-black); text-decoration: underline; text-underline-offset: 2px; }
a:hover { color: var(--medium-gray); }
a:visited { color: var(--dark-gray); }

strong { font-weight: 700; }
em { font-style: italic; }
code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--near-white);
  border: 1px solid var(--border-light);
  padding: 0.1em 0.35em;
  border-radius: 2px;
}

blockquote {
  border-left: 4px solid var(--black);
  padding: 0.8rem 1.2rem;
  margin: 1.5rem 0;
  background: var(--near-white);
  font-style: italic;
}

hr {
  border: none;
  border-top: 1px solid var(--border-light);
  margin: 2rem 0;
}

/* --- Page Layout --- */
.site-header {
  background: var(--black);
  color: var(--white);
  padding: 0;
  border-bottom: 4px double var(--white);
  position: sticky;
  top: 0;
  z-index: 1000;
}

.header-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1.5rem;
}

.site-logo {
  font-family: var(--font-heading);
  font-size: 1.4rem;
  font-weight: 900;
  color: var(--white);
  text-decoration: none;
  letter-spacing: 0.08em;
}
.site-logo:hover { color: var(--light-gray); }
.site-logo:visited { color: var(--white); }

.site-logo .tilde {
  display: inline-block;
  animation: tildePulse 3s ease-in-out infinite;
}

@keyframes tildePulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.header-nav { display: flex; gap: 1.2rem; align-items: center; }
.header-nav a {
  color: var(--light-gray);
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-bottom: 1px solid transparent;
  padding-bottom: 2px;
  transition: border-color 0.2s;
}
.header-nav a:hover { border-bottom-color: var(--white); color: var(--white); }
.header-nav a:visited { color: var(--light-gray); }

/* --- Main Content Area --- */
.page-wrapper {
  max-width: var(--max-width);
  margin: 0 auto;
  display: flex;
  min-height: calc(100vh - 60px);
}

.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--near-white);
  border-right: 1px solid var(--border-light);
  padding: 1.5rem 0;
  position: sticky;
  top: 52px;
  height: calc(100vh - 52px);
  overflow-y: auto;
  font-size: 0.82rem;
}

.sidebar-section { margin-bottom: 1.5rem; }
.sidebar-section-title {
  font-family: var(--font-heading);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--medium-gray);
  padding: 0 1.2rem;
  margin-bottom: 0.4rem;
}

.sidebar a {
  display: block;
  padding: 0.3rem 1.2rem;
  color: var(--near-black);
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: all 0.15s;
  line-height: 1.4;
}
.sidebar a:hover {
  background: var(--white);
  border-left-color: var(--black);
}
.sidebar a:visited { color: var(--near-black); }
.sidebar a.active {
  background: var(--white);
  border-left-color: var(--black);
  font-weight: 700;
}

.main-content {
  flex: 1;
  padding: 2rem 2.5rem;
  min-width: 0;
}

/* --- Breadcrumbs --- */
.breadcrumb {
  font-size: 0.78rem;
  color: var(--gray);
  margin-bottom: 1.5rem;
}
.breadcrumb a { color: var(--medium-gray); }

/* --- Module Header --- */
.module-header {
  margin-bottom: 2rem;
  padding-bottom: 1rem;
}
.module-number {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--gray);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.module-title {
  font-size: 2rem;
  border-bottom: 3px double var(--black);
  padding-bottom: 0.5rem;
  margin-top: 0.3rem;
}

/* --- Content Boxes --- */
.info-box, .caution-box, .advanced-box, .example-box, .quiz-box, .source-box, .rule-variant-box {
  border: 1px solid var(--border);
  padding: 1.2rem 1.5rem;
  margin: 1.5rem 0;
  position: relative;
}

.info-box { background: var(--near-white); }
.info-box::before { content: '■ NOTE'; }

.caution-box { border-width: 2px; background: var(--near-white); }
.caution-box::before { content: '▲ CAUTION'; }

.advanced-box { border-style: dashed; }
.advanced-box::before { content: '◆ ADVANCED'; }

.example-box { border-left: 5px solid var(--black); }
.example-box::before { content: '● EXAMPLE'; }

.quiz-box { border: 2px solid var(--black); background: var(--near-white); }
.quiz-box::before { content: '✦ QUIZ'; }

.source-box { border-style: dotted; font-size: 0.88rem; color: var(--medium-gray); }
.source-box::before { content: '◇ SOURCES'; }

.rule-variant-box { border-left: 5px solid var(--gray); background: var(--near-white); }
.rule-variant-box::before { content: '⚙ RULESET VARIANT'; }

.info-box::before, .caution-box::before, .advanced-box::before,
.example-box::before, .quiz-box::before, .source-box::before,
.rule-variant-box::before {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  margin-bottom: 0.8rem;
  color: var(--medium-gray);
}

/* --- Tables --- */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-size: 0.9rem;
}
th, td {
  border: 1px solid var(--border);
  padding: 0.5rem 0.8rem;
  text-align: left;
  vertical-align: top;
}
th {
  background: var(--black);
  color: var(--white);
  font-weight: 700;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
tr:nth-child(even) { background: var(--near-white); }

/* --- Tile Notation Display --- */
.tile-display {
  font-family: var(--font-mono);
  font-size: 1rem;
  background: var(--near-white);
  border: 1px solid var(--border-light);
  padding: 0.6rem 0.8rem 0.4rem;
  margin: 1rem 0;
  letter-spacing: 0.02em;
  line-height: 1.2;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0;
}
.tile-display.tile-rendered {
  font-size: inherit;
}

.tile-em {
  font-size: 4rem;
  line-height: 1;
  display: block;
  cursor: default;
}
.tile-em.tile-hl {
  background: var(--near-white);
  border-bottom: 2px solid var(--black);
}
.tile-unit {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  vertical-align: top;
  margin: 0 1px;
  text-align: center;
}
.tile-unit.tile-hl {
  background: var(--near-white);
  border-bottom: 2px solid var(--black);
}
.tile-unit.tile-inline {
  vertical-align: middle;
}
.tile-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.6rem;
  font-weight: 600;
  color: var(--gray);
  line-height: 1;
  margin-top: -2px;
  letter-spacing: 0.03em;
}
.tile-sep {
  display: inline-flex;
  align-items: center;
  width: 0.8rem;
  text-align: center;
  font-size: 1.8rem;
  color: var(--gray);
  align-self: center;
  margin: 0 0.1rem;
}
.tile-text {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--medium-gray);
  align-self: center;
  margin: 0 0.3rem;
  line-height: 1.4;
}
.tile-code {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  background: var(--white);
  border: 1px solid var(--border-light);
  padding: 0.1em 0.3em;
  border-radius: 2px;
  vertical-align: middle;
}

.tile {
  display: inline-block;
  width: 30px;
  height: 42px;
  border: 2px solid var(--black);
  border-radius: 3px;
  background: var(--white);
  text-align: center;
  line-height: 42px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 700;
  margin: 2px;
  vertical-align: middle;
  position: relative;
}
.tile.called {
  border-color: var(--gray);
  background: var(--near-white);
}
.tile.dora {
  border-width: 3px;
}
.tile-gap {
  display: inline-block;
  width: 10px;
}

/* --- SVG Diagrams --- */
.diagram-container {
  margin: 1.5rem 0;
  text-align: center;
}
.diagram-container svg {
  max-width: 100%;
  height: auto;
}
.diagram-caption {
  font-size: 0.8rem;
  color: var(--medium-gray);
  margin-top: 0.5rem;
  font-style: italic;
}

/* --- Quiz System --- */
.quiz-question {
  margin: 1.5rem 0;
  padding: 1.2rem;
  border: 1px solid var(--border);
  background: var(--near-white);
}
.quiz-question h4 {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--medium-gray);
  margin-bottom: 0.8rem;
}
.quiz-options { list-style: none; margin: 0.8rem 0; }
.quiz-options li {
  padding: 0.5rem 0.8rem;
  margin: 0.3rem 0;
  border: 1px solid var(--border-light);
  cursor: pointer;
  transition: background 0.15s;
  font-size: 0.92rem;
}
.quiz-options li:hover { background: var(--white); border-color: var(--black); }
.quiz-options li.selected { border-color: var(--black); border-width: 2px; font-weight: 500; }
.quiz-options li.correct { background: var(--near-white); border-color: var(--black); border-width: 2px; }
.quiz-options li.incorrect { border-style: dashed; color: var(--gray); }

.quiz-reveal {
  display: none;
  margin-top: 1rem;
  padding: 1rem;
  border-top: 2px solid var(--black);
  font-size: 0.92rem;
}
.quiz-reveal.visible { display: block; }

.quiz-btn {
  display: inline-block;
  padding: 0.5rem 1.5rem;
  border: 2px solid var(--black);
  background: var(--white);
  color: var(--black);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.05em;
  transition: all 0.15s;
  margin-top: 0.5rem;
}
.quiz-btn:hover {
  background: var(--black);
  color: var(--white);
}

/* --- Navigation Footer --- */
.page-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 2px solid var(--black);
}
.page-nav a {
  font-size: 0.88rem;
  font-weight: 500;
  text-decoration: none;
  padding: 0.5rem 0;
  border-bottom: 1px solid transparent;
}
.page-nav a:hover { border-bottom-color: var(--black); }
.page-nav .prev::before { content: '← '; }
.page-nav .next::after { content: ' →'; }

/* --- Footer --- */
.site-footer {
  background: var(--black);
  color: var(--gray);
  text-align: center;
  padding: 1.5rem;
  font-size: 0.78rem;
  letter-spacing: 0.05em;
  border-top: 4px double var(--gray);
}

/* --- Dashboard Specific --- */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1rem;
  margin: 1.5rem 0;
}

.topic-card {
  border: 1px solid var(--border);
  padding: 1rem 1.2rem;
  transition: border-color 0.15s;
}
.topic-card:hover { border-color: var(--black); }
.topic-card a { text-decoration: none; }
.topic-card .card-number {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--gray);
}
.topic-card .card-title {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1rem;
  color: var(--black);
  margin: 0.3rem 0;
}
.topic-card .card-desc {
  font-size: 0.82rem;
  color: var(--medium-gray);
  line-height: 1.5;
}

/* --- Glossary --- */
.glossary-entry {
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px dotted var(--border-light);
}
.glossary-term {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1.05rem;
}
.glossary-reading {
  font-size: 0.88rem;
  color: var(--gray);
  margin-left: 0.5rem;
}
.glossary-def {
  margin-top: 0.3rem;
  font-size: 0.92rem;
}

/* --- Flow Charts (CSS-based) --- */
.flow-step {
  border: 2px solid var(--black);
  padding: 0.8rem 1.2rem;
  margin: 0.5rem auto;
  max-width: 400px;
  text-align: center;
  font-size: 0.9rem;
  position: relative;
}
.flow-arrow {
  text-align: center;
  font-size: 1.5rem;
  line-height: 1;
  margin: 0.2rem 0;
}

/* --- Progress Bar --- */
.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--near-white);
  border: 1px solid var(--border-light);
  margin: 0.5rem 0;
}
.progress-fill {
  height: 100%;
  background: var(--black);
}

/* --- Responsive --- */
@media (max-width: 900px) {
  .page-wrapper { flex-direction: column; }
  .sidebar {
    width: 100%;
    min-width: 100%;
    height: auto;
    position: relative;
    top: 0;
    border-right: none;
    border-bottom: 1px solid var(--border-light);
    max-height: 300px;
  }
  .main-content { padding: 1.5rem; }
  .dashboard-grid { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  .header-nav a { display: none; }
  .header-nav { gap: 0.3rem; }
  .a11y-toggles { margin-left: 0; }
  h1 { font-size: 1.5rem; }
  .module-title { font-size: 1.5rem; }
  .main-content { padding: 1rem; }
  .tile-em { font-size: 2.5rem; }
}

/* --- Utility --- */
.text-center { text-align: center; }
.text-small { font-size: 0.85rem; }
.text-muted { color: var(--medium-gray); }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }

/* --- Print --- */
@media print {
  .site-header, .sidebar, .site-footer, .page-nav { display: none; }
  .main-content { padding: 0; max-width: 100%; }
  body { font-size: 11pt; }
}

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--near-white); }
::-webkit-scrollbar-thumb { background: var(--gray); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--medium-gray); }
