/* ==========================================================================
   Design Tokens
   ========================================================================== */

:root {
  /* Fixed Brand Colors */
  --mj-green: #0a5c3a;
  --mj-gold: #c8952a;
  --mj-red: #c0392b;
  --tile-bg: #f9f4eb;
  --tile-border: #d4b87a;
  
  /* Theme Colors (Light Mode Default) */
  --color-background-primary: #f4f6f8;
  --color-background-secondary: #ffffff;
  --color-border-tertiary: rgba(0, 0, 0, 0.08);
  --color-border-secondary: rgba(0, 0, 0, 0.15);
  --color-text-primary: #1e293b;
  --color-text-secondary: #475569;
  --color-text-tertiary: #94a3b8;
  
  /* Typography & Layout */
  --font-sans: 'Inter', 'Noto Sans CJK TC', 'Microsoft JhengHei', sans-serif;
  --border-radius-md: 8px;
  --border-radius-lg: 12px;
}

/* Dark Mode Theme */
@media (prefers-color-scheme: dark) {
  :root {
    --color-background-primary: #0f172a;
    --color-background-secondary: #1e293b;
    --color-border-tertiary: rgba(255, 255, 255, 0.1);
    --color-border-secondary: rgba(255, 255, 255, 0.2);
    --color-text-primary: #f8fafc;
    --color-text-secondary: #cbd5e1;
    --color-text-tertiary: #64748b;
  }
}

/* ==========================================================================
   Global Reset & Base
   ========================================================================== */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background-color: #e2e8f0;
  color: var(--color-text-primary);
  display: flex;
  justify-content: center;
  padding: 24px;
  min-height: 100vh;
}

@media (prefers-color-scheme: dark) {
  body {
    background-color: #020617;
  }
}

button {
  font-family: inherit;
  border: none;
  background: none;
  cursor: pointer;
}

h2, h3, h4 {
  color: var(--color-text-primary);
}

/* ==========================================================================
   App Shell & Navigation (Spec 00)
   ========================================================================== */

.app-shell {
  width: 100%;
  max-width: 800px;
  min-height: 600px;
  background: var(--color-background-primary);
  border-radius: var(--border-radius-lg);
  overflow: hidden;
  border: 0.5px solid var(--color-border-tertiary);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.05);
  display: flex;
  flex-direction: column;
}

@media (prefers-color-scheme: dark) {
  .app-shell {
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
  }
}

.nav-header {
  background: var(--mj-green);
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 14px;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-tile {
  width: 36px;
  height: 44px;
  background: var(--tile-bg);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  border: 2px solid var(--tile-border);
  box-shadow: 2px 2px 0 rgba(0,0,0,0.25);
  font-weight: 700;
  color: var(--mj-red);
  line-height: 1;
}

.brand-text-group {
  display: flex;
  flex-direction: column;
}

.brand-text {
  color: #ffffff;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.brand-sub {
  color: rgba(255,255,255,0.7);
  font-size: 11px;
  margin-top: 2px;
  font-weight: 500;
}

.nav-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.nav-tab {
  background: rgba(255,255,255,0.12);
  border: 0.5px solid rgba(255,255,255,0.2);
  color: rgba(255,255,255,0.8);
  padding: 6px 13px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.nav-tab:hover {
  background: rgba(255,255,255,0.2);
  color: #ffffff;
}

.nav-tab.active {
  background: var(--mj-gold);
  border-color: var(--mj-gold);
  color: #ffffff;
  box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.section-container {
  flex: 1;
  position: relative;
  overflow-y: auto;
}

.section {
  display: none;
  padding: 24px;
  animation: fadeIn 0.3s ease;
}

.section.active {
  display: block;
}

.section-subtitle {
  font-size: 14px;
  color: var(--color-text-secondary);
  line-height: 1.6;
  margin-top: 6px;
  margin-bottom: 24px;
  max-width: 600px;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 500px) {
  .nav-tabs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    width: 100%;
  }
  .nav-tab {
    text-align: center;
    padding: 8px 6px;
  }
  .section {
    padding: 16px;
  }
}

/* ==========================================================================
   Shared Sub-Components
   ========================================================================== */

.divider {
  height: 0.5px;
  background: var(--color-border-tertiary);
  margin: 24px 0;
}

.flow-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 16px;
}

.info-card {
  background: var(--color-background-secondary);
  border: 0.5px solid var(--color-border-tertiary);
  border-radius: var(--border-radius-md);
  padding: 16px;
  transition: transform 0.2s, box-shadow 0.2s;
}

.info-card:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.05);
  border-color: var(--color-border-secondary);
}

.info-card i {
  font-size: 20px;
  color: var(--mj-gold);
  margin-bottom: 8px;
  display: block;
}

.info-card h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 6px;
}

.info-card p {
  font-size: 13px;
  color: var(--color-text-secondary);
  line-height: 1.6;
}

.alert-box {
  background: #fef6e4;
  border: 0.5px solid #f0c060;
  border-left: 3px solid var(--mj-gold);
  border-radius: 0 var(--border-radius-md) var(--border-radius-md) 0;
  padding: 12px 16px;
  font-size: 13px;
  color: #7a5a12;
  margin: 16px 0;
  line-height: 1.6;
}

.alert-box strong {
  font-weight: 600;
}

.pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}

.pill-gold { background: #fef6e4; color: #9a6f1a; border: 1px solid rgba(154, 111, 26, 0.2); }
.pill-green { background: #e8f5ef; color: var(--mj-green); border: 1px solid rgba(10, 92, 58, 0.2); }
.pill-blue { background: #e6f1fb; color: #185fa5; border: 1px solid rgba(24, 95, 165, 0.2); }
.pill-red { background: #fdecea; color: var(--mj-red); border: 1px solid rgba(192, 57, 43, 0.2); }
.pill-gray { background: var(--color-background-secondary); color: var(--color-text-secondary); border: 1px solid var(--color-border-secondary); }

.small-tile {
  width: 34px;
  height: 42px;
  background: var(--tile-bg);
  border-radius: 4px;
  border: 1.5px solid var(--tile-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 500;
  box-shadow: 1px 1px 0 rgba(0,0,0,0.12);
}

.combination-demo {
  background: var(--color-background-secondary);
  border: 0.5px solid var(--color-border-tertiary);
  border-radius: var(--border-radius-md);
  padding: 16px;
  margin-bottom: 16px;
}

.combination-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.combination-header h4 {
  font-size: 14px;
  font-weight: 600;
}

.combination-tiles {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 12px;
  align-items: center;
}

.combination-desc {
  font-size: 12px;
  color: var(--color-text-secondary);
  line-height: 1.5;
}

/* ==========================================================================
   Overview Section (Spec 01)
   ========================================================================== */

.key-facts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
}

.step-flow {
  display: flex;
  flex-direction: column;
}

.step {
  display: flex;
  gap: 16px;
  padding: 16px 0;
  border-bottom: 0.5px solid var(--color-border-tertiary);
}

.step:last-child {
  border-bottom: none;
}

.step-badge {
  width: 28px;
  height: 28px;
  background: var(--mj-green);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
}

.step-content h4 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
}

.step-content p {
  font-size: 13px;
  color: var(--color-text-secondary);
  line-height: 1.6;
}

/* ==========================================================================
   Tiles Section (Spec 02)
   ========================================================================== */

.tile-info-panel {
  background: var(--color-background-secondary);
  border: 1px solid var(--color-border-tertiary);
  border-radius: var(--border-radius-md);
  padding: 12px 16px;
  font-size: 13px;
  color: var(--color-text-secondary);
  min-height: 44px;
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  transition: all 0.2s;
}

.tile-group-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-tertiary);
  margin: 20px 0 10px 0;
  display: flex;
  align-items: center;
}

.tile-group-label::after {
  content: '';
  flex: 1;
  height: 0.5px;
  background: var(--color-border-tertiary);
  margin-left: 10px;
}

.tile-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.tile-item {
  width: 46px;
  height: 58px;
  background: var(--tile-bg);
  border: 1.5px solid var(--tile-border);
  border-radius: 5px;
  box-shadow: 2px 2px 0 rgba(0,0,0,0.14);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  cursor: pointer;
  transition: transform 0.15s cubic-bezier(0.2, 0, 0, 1), box-shadow 0.15s ease, border-color 0.15s ease, background-color 0.15s ease;
  position: relative;
}

.tile-item:hover {
  transform: translateY(-4px);
  box-shadow: 2px 6px 0 rgba(0,0,0,0.16);
}

.tile-item.selected {
  transform: translateY(-8px);
  box-shadow: 2px 10px 0 rgba(0,0,0,0.18);
  border-color: var(--mj-green);
  background: #e8f5ef;
}

.tile-item .bonus-label {
  font-size: 8px;
  color: #888;
  position: absolute;
  bottom: 2px;
  font-weight: 400;
}

/* Suit Colors */
.color-man { color: var(--mj-red); }
.color-bam { color: var(--mj-green); }
.color-dot { color: #1a4a8a; }
.color-wind { color: #333333; }
.color-dragon-red { color: var(--mj-red); }
.color-dragon-green { color: var(--mj-green); }
.color-dragon-white { color: #555555; }
.color-bonus-flower { color: var(--mj-red); }
.color-bonus-season { color: #1a4a8a; }

.fw-bold { font-weight: 700 !important; }

.explainer-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 16px;
}

/* ==========================================================================
   Gameplay Section (Spec 03)
   ========================================================================== */

.practice-board {
  background: #1a6b45; /* Dark felt green */
  border-radius: var(--border-radius-md);
  padding: 20px;
  margin: 16px 0;
  box-shadow: inset 0 2px 10px rgba(0,0,0,0.2);
}

.board-label {
  color: rgba(255,255,255,0.6);
  font-size: 11px;
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

.hand-area {
  background: rgba(0,0,0,0.15);
  border-radius: 6px;
  padding: 12px;
  min-height: 66px;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  align-items: center;
}

/* Interactive small tiles in hand */
.hand-area .small-tile {
  cursor: pointer;
  transition: transform 0.15s ease;
}

.hand-area .small-tile:hover {
  transform: translateY(-3px);
}

.discard-message {
  color: rgba(255,255,255,0.8);
  font-size: 13px;
  margin-top: 12px;
  min-height: 20px;
}

.action-bar {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.board-btn {
  background: rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.9);
  border: 0.5px solid rgba(255,255,255,0.25);
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s;
}

.board-btn:hover {
  background: rgba(255,255,255,0.25);
}

.board-btn.btn-check {
  background: rgba(200,149,42,0.8);
  border-color: rgba(200,149,42,0.9);
  color: white;
}
.board-btn.btn-check:hover {
  background: rgba(200,149,42,0.95);
}

.win-breakdown {
  background: rgba(0, 0, 0, 0.2);
  border-radius: var(--border-radius-md);
  padding: 16px;
  margin-top: 16px;
  font-size: 13px;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.1);
}
.win-breakdown h4 {
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--mj-gold);
}
.win-breakdown .bd-row {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px dashed rgba(255,255,255,0.2);
  padding: 6px 0;
}
.win-breakdown .bd-row:last-of-type {
  border-bottom: none;
}
.win-breakdown .bd-total {
  display: flex;
  justify-content: space-between;
  font-weight: 600;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(255,255,255,0.4);
  font-size: 14px;
}
.win-breakdown .bd-total .val {
  color: var(--mj-gold);
}
.win-breakdown .bd-pay {
  margin-top: 8px;
  color: rgba(255,255,255,0.8);
  font-size: 12px;
  text-align: right;
}

/* ==========================================================================
   Winning Section (Spec 04)
   ========================================================================== */

.filter-toggle {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.filter-chip {
  background: transparent;
  border: 1px solid var(--color-border-secondary);
  color: var(--color-text-secondary);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  transition: all 0.15s;
}

.filter-chip:hover {
  background: var(--color-border-tertiary);
}

.filter-chip.active {
  background: var(--mj-green);
  border-color: var(--mj-green);
  color: white;
}

.highlight-win-tile {
  border-color: var(--mj-gold) !important;
  background: #fef6e4 !important;
  position: relative;
}

.separator-text {
  font-size: 11px;
  color: var(--color-text-tertiary);
  margin: 0 4px;
}

/* ==========================================================================
   Scoring Section (Spec 05)
   ========================================================================== */

.table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--color-border-tertiary);
  border-radius: var(--border-radius-md);
  margin-bottom: 16px;
}

.scoring-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 400px;
}

.scoring-table th {
  background: var(--mj-green);
  color: white;
  padding: 12px 14px;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
}

.scoring-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--color-border-tertiary);
  color: var(--color-text-primary);
  vertical-align: top;
  line-height: 1.5;
}

.scoring-table tr:last-child td {
  border-bottom: none;
}

.scoring-table tr:nth-child(even) td {
  background: var(--color-background-secondary);
}

.scoring-table .pts {
  font-weight: 600;
  color: #9a6f1a;
  white-space: nowrap;
}

.instruction-text {
  font-size: 13px;
  color: var(--color-text-secondary);
  margin-bottom: 14px;
}

.calculator-toggles {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

/* Reusing .filter-chip styling for calculator toggles */
.calc-chip {
  background: transparent;
  border: 1px solid var(--color-border-secondary);
  color: var(--color-text-secondary);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  transition: all 0.15s;
}

.calc-chip.active {
  background: var(--mj-green);
  border-color: var(--mj-green);
  color: white;
}

.score-calc {
  background: var(--color-background-secondary);
  border: 1px solid var(--color-border-tertiary);
  border-radius: var(--border-radius-lg);
  padding: 20px;
  margin: 16px 0;
  box-shadow: 0 4px 6px rgba(0,0,0,0.02);
}

.score-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px dashed var(--color-border-tertiary);
  font-size: 13px;
}

.score-row .label {
  color: var(--color-text-secondary);
}

.score-row .val {
  font-weight: 600;
  color: var(--color-text-primary);
}

.score-row.total {
  border-bottom: none;
  padding-top: 16px;
  margin-top: 6px;
}

.score-row.total .label {
  font-weight: 600;
  color: var(--color-text-primary);
  font-size: 14px;
}

.score-row.total .val {
  color: var(--mj-gold);
  font-size: 18px;
}

.payment-row {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--color-border-tertiary);
  text-align: right;
}

.payment-row .pay-label {
  font-size: 12px;
  color: var(--color-text-tertiary);
  margin-bottom: 4px;
}

.payment-row .pay-val {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text-primary);
}

.footer-note {
  font-size: 12px;
  color: var(--color-text-tertiary);
  margin-top: 8px;
  line-height: 1.5;
}

/* ==========================================================================
   Quiz Section (Spec 06)
   ========================================================================== */

.progress-bar-wrap {
  background: var(--color-border-secondary);
  border-radius: 20px;
  height: 6px;
  overflow: hidden;
  margin-bottom: 8px;
}

.progress-bar-fill {
  height: 100%;
  background: var(--mj-green);
  border-radius: 20px;
  transition: width 0.3s ease;
}

.progress-label {
  font-size: 12px;
  color: var(--color-text-secondary);
  margin-bottom: 24px;
  font-weight: 500;
}

.quiz-card {
  max-width: 560px;
  margin: 0 auto 0 0;
}

.quiz-question {
  font-size: 16px;
  font-weight: 600;
  color: var(--color-text-primary);
  line-height: 1.5;
  margin-bottom: 20px;
}

.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.quiz-opt {
  background: var(--color-background-secondary);
  border: 1px solid var(--color-border-tertiary);
  border-radius: var(--border-radius-md);
  padding: 14px 16px;
  font-size: 14px;
  cursor: pointer;
  color: var(--color-text-primary);
  text-align: left;
  width: 100%;
  transition: all 0.15s;
  font-weight: 500;
}

.quiz-opt:hover:not(:disabled) {
  border-color: var(--color-border-secondary);
  background: var(--color-background-primary);
}

.quiz-opt.correct {
  background: #e8f5ef !important;
  border-color: var(--mj-green) !important;
  color: var(--mj-green) !important;
}

.quiz-opt.wrong {
  background: #fdecea !important;
  border-color: var(--mj-red) !important;
  color: var(--mj-red) !important;
}

.quiz-opt:disabled {
  cursor: not-allowed;
  opacity: 0.8;
}

.quiz-feedback {
  font-size: 13px;
  color: var(--color-text-secondary);
  padding: 14px;
  background: var(--color-background-secondary);
  border: 1px solid var(--color-border-tertiary);
  border-radius: var(--border-radius-md);
  margin-top: 16px;
  line-height: 1.6;
  display: none;
}

.btn-primary {
  background: var(--mj-green);
  color: white;
  padding: 12px 20px;
  border-radius: var(--border-radius-md);
  font-size: 14px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: background 0.2s;
  box-shadow: 0 2px 6px rgba(10, 92, 58, 0.3);
}

.btn-primary:hover {
  background: #08492e;
}

/* Results Screen */
.results-content {
  text-align: center;
  padding: 40px 0;
}

.results-emoji {
  font-size: 56px;
  margin-bottom: 16px;
  line-height: 1;
}

.results-grade {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 8px;
}

.results-score-line {
  font-size: 16px;
  color: var(--color-text-secondary);
  margin-bottom: 24px;
}
