/* =============================================================
   Mahjong Learning App
   Imports design tokens from style.css via cascade.
   ============================================================= */

/* -------------------------------------------------------------
   SVG / PNG TILE FACE
   Sits inside the CSS tile shell.
   ------------------------------------------------------------- */

.tile-face {
    display: block;
    width: 34px;
    height: 50px;
    object-fit: contain;
}
.tile.tile-xl .tile-face { width: 50px; height: 72px; }
.tile.tile-sm .tile-face { width: 24px; height: 36px; }

/* -------------------------------------------------------------
   TILE SHELL — BASE
   ------------------------------------------------------------- */

.tile {
    width: 44px;
    height: 62px;
    background: #F7F0E6;
    border: 1.5px solid #8C7A5E;
    border-bottom: 2.5px solid #6B5A42;
    border-radius: 4px 4px 5px 5px;
    box-shadow:
        0 4px 0 #B8A48A,
        0 6px 12px rgba(0, 0, 0, 0.22);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    transition: transform 0.12s ease, box-shadow 0.12s ease;
    cursor: default;
    user-select: none;
    flex-shrink: 0;
}

/* -------------------------------------------------------------
   TILE SIZES
   ------------------------------------------------------------- */

.tile.tile-sm {
    width: 32px;
    height: 45px;
}

.tile.tile-xl {
    width: 64px;
    height: 90px;
}

/* -------------------------------------------------------------
   FLOWER / SEASON TILES (HK only) — tinted shell
   ------------------------------------------------------------- */

.tile-flower {
    background: #FFFBF0;
}

.tile-season {
    background: #F0F6FF;
}

/* -------------------------------------------------------------
   INTERACTIVE STATES
   ------------------------------------------------------------- */

.tile.is-interactive {
    cursor: pointer;
}

.tile.is-interactive:hover {
    transform: translateY(-3px);
    box-shadow: 0 7px 0 #B8A48A, 0 10px 18px rgba(0, 0, 0, 0.28);
}

.tile.is-selected {
    transform: translateY(-6px);
    box-shadow: 0 10px 0 #B8A48A, 0 14px 20px rgba(0, 0, 0, 0.3);
    border-color: var(--primary);
}

.tile.is-correct {
    border-color: #2A7A4F;
    box-shadow: 0 4px 0 #1E5C3A, 0 6px 16px rgba(42, 122, 79, 0.3);
}

.tile.is-wrong {
    border-color: var(--error);
    box-shadow: 0 4px 0 #A82030, 0 6px 16px rgba(242, 48, 65, 0.3);
    animation: tile-shake 0.4s ease;
}

.tile.flip-in {
    animation: tile-flip-in 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.tile.bounce {
    animation: tile-bounce 0.4s ease;
}

/* -------------------------------------------------------------
   TILE ANIMATIONS
   ------------------------------------------------------------- */

@keyframes tile-shake {
    0%, 100% { transform: translateX(0); }
    20%       { transform: translateX(-4px); }
    40%       { transform: translateX(4px); }
    60%       { transform: translateX(-3px); }
    80%       { transform: translateX(3px); }
}

@keyframes tile-flip-in {
    from { transform: rotateY(90deg) scale(0.9); opacity: 0; }
    to   { transform: rotateY(0deg) scale(1);   opacity: 1; }
}

@keyframes tile-bounce {
    0%, 100% { transform: translateY(0); }
    40%      { transform: translateY(-8px) scale(1.08); }
    70%      { transform: translateY(-2px) scale(1.02); }
}

/* -------------------------------------------------------------
   TILE GROUPS (sets: pung, chow, kong)
   ------------------------------------------------------------- */

.tile-group {
    display: flex;
    gap: 6px;
    align-items: flex-end;
}

.tile-group.is-complete {
    padding: 10px 12px 8px;
    background: rgba(255, 255, 255, 0.7);
    border-radius: var(--radius-card);
    border: var(--border-width) solid var(--black);
    box-shadow: var(--shadow-button);
    width: fit-content;
}

.tile-group-label {
    font-family: var(--font-mono);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--black50);
    display: block;
    text-align: center;
    margin-top: 8px;
}

/* Hand display — a row of tiles */
.hand-display {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    justify-content: center;
    align-items: flex-end;
}

.hand-display-label {
    font-family: var(--font-mono);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--black50);
    display: block;
    text-align: center;
    margin-bottom: 8px;
}

/* Separator between hand tiles and the discard tile in scenarios */
.hand-discard-separator {
    width: 100%;
    height: 1px;
    background: var(--black10);
    margin: 20px 0;
}

/* -------------------------------------------------------------
   MAHJONG APP LAYOUT
   ------------------------------------------------------------- */

.mahjong-view {
    min-height: 60vh;
}

/* Progress bar */
.mahjong-progress-bar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--primary--orange---light-95);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-bottom: 1.5px solid var(--black10);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
}

.progress-track {
    flex: 1;
    height: 4px;
    background: var(--black10);
    border-radius: 2px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 2px;
    width: 0%;
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.progress-label {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--black50);
    white-space: nowrap;
}

.progress-back-btn,
.progress-home-btn {
    background: none;
    border: none;
    font-size: 16px;
    cursor: pointer;
    color: var(--black50);
    padding: 4px 8px;
    border-radius: 4px;
    transition: color 0.15s, background 0.15s;
    font-family: var(--font-mono);
    line-height: 1;
}

.progress-back-btn:hover,
.progress-home-btn:hover {
    color: var(--black);
    background: var(--black10);
}

/* -------------------------------------------------------------
   VARIANT SELECTOR VIEW
   ------------------------------------------------------------- */

.selector-container {
    max-width: 680px;
    margin: 0 auto;
    padding: 60px 24px 80px;
}

.mahjong-hero {
    font-family: var(--font-family);
    font-size: var(--h2);
    font-weight: 700;
    color: var(--black);
    margin: 0 0 12px;
    line-height: 1.1;
}

.mahjong-subtitle {
    font-family: var(--second-family);
    font-size: var(--paragraph-larger);
    color: var(--black75);
    margin: 0 0 48px;
    line-height: 1.5;
}

.variant-cards {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.variant-card {
    display: flex;
    align-items: center;
    gap: 20px;
    width: 100%;
    background: #fff;
    border: var(--border-width) solid transparent;
    border-radius: var(--radius-card);
    padding: 20px 24px;
    text-align: left;
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s, transform 0.12s;
    box-shadow: var(--shadow-button);
    position: relative;
}

.variant-card:hover {
    border-color: var(--black);
    box-shadow: var(--shadow-hover);
    transform: translateY(-1px);
}

.variant-card:active {
    transform: translateY(0);
    box-shadow: var(--shadow-active);
}

.variant-card.is-coming-soon {
    opacity: 0.5;
    cursor: not-allowed;
}

.variant-card.is-coming-soon:hover {
    border-color: transparent;
    box-shadow: var(--shadow-button);
    transform: none;
}

.variant-card.is-complete {
    border-color: var(--primary);
}

.variant-card-tiles {
    display: flex;
    align-items: flex-end;
    flex-shrink: 0;
}

.variant-card-tiles .tile:not(:first-child) {
    margin-left: -10px;
}

.variant-card-info {
    flex: 1;
    min-width: 0;
}

.variant-name {
    font-family: var(--font-family);
    font-size: var(--h6);
    font-weight: 700;
    color: var(--black);
    margin: 0 0 2px;
    line-height: 1.2;
}

.variant-origin {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--black50);
    margin: 0 0 8px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.variant-desc {
    font-family: var(--second-family);
    font-size: var(--paragraph);
    color: var(--black75);
    margin: 0 0 12px;
    line-height: 1.5;
}

.variant-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.variant-tag {
    font-family: var(--font-mono);
    font-size: 10px;
    padding: 2px 8px;
    border: 1.5px solid var(--black25);
    border-radius: 12px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--black75);
}

.variant-card-arrow {
    font-size: 20px;
    color: var(--black25);
    flex-shrink: 0;
    font-family: var(--font-mono);
    transition: color 0.15s, transform 0.15s;
}

.variant-card:hover .variant-card-arrow {
    color: var(--black);
    transform: translateX(3px);
}

.coming-soon-badge {
    position: absolute;
    top: 12px;
    right: 12px;
    font-family: var(--font-mono);
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    background: var(--black10);
    color: var(--black50);
    padding: 2px 8px;
    border-radius: 10px;
}

.complete-badge {
    position: absolute;
    top: 12px;
    right: 12px;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--primary);
    font-weight: 700;
}

.variant-resume {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--primary);
    margin: 4px 0 0;
    display: block;
}

.selector-reset {
    display: block;
    margin: 32px auto 0;
    text-align: center;
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--error);
    background: none;
    border: none;
    cursor: pointer;
    text-decoration: underline;
    opacity: 0.7;
    transition: opacity 0.15s;
}

.selector-reset:hover {
    opacity: 1;
}

/* -------------------------------------------------------------
   LESSON VIEW
   ------------------------------------------------------------- */

.lesson-container {
    max-width: 580px;
    margin: 0 auto;
    padding: 48px 24px 80px;
}

.lesson-chapter-label {
    font-family: var(--font-mono);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--black50);
    margin: 0 0 16px;
    display: block;
}

.lesson-heading {
    font-family: var(--font-family);
    font-size: var(--h4);
    font-weight: 700;
    color: var(--black);
    margin: 0 0 20px;
    line-height: 1.15;
}

.lesson-body {
    font-family: var(--second-family);
    font-size: var(--paragraph-larger);
    color: var(--black75);
    margin: 0 0 28px;
    line-height: 1.65;
}

.lesson-tile-display {
    background: #fff;
    border: var(--border-width) solid var(--black);
    border-radius: var(--radius-card);
    padding: 24px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    align-items: flex-end;
    margin: 0 0 20px;
    box-shadow: var(--shadow-button);
}

.lesson-tile-caption {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--black50);
    text-align: center;
    margin: 0 0 28px;
    text-transform: uppercase;
    letter-spacing: 0.07em;
}

.lesson-callout {
    background: var(--primary--orange---light-active);
    border-left: 4px solid var(--primary);
    border-radius: 0 var(--radius-card) var(--radius-card) 0;
    padding: 14px 18px;
    font-family: var(--second-family);
    font-style: italic;
    font-size: var(--paragraph);
    color: var(--black);
    margin: 0 0 28px;
    line-height: 1.55;
}

.lesson-comparison {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    justify-content: center;
    margin: 0 0 20px;
}

.lesson-comparison-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.lesson-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 40px;
    padding-top: 20px;
    border-top: 1.5px solid var(--black10);
}

.lesson-back-link {
    font-family: var(--second-family);
    font-size: var(--paragraph);
    color: var(--black50);
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    transition: color 0.15s;
    text-decoration: underline;
}

.lesson-back-link:hover {
    color: var(--black);
}

.lesson-next-btn {
    font-family: var(--second-family);
    font-size: var(--paragraph);
    font-weight: 600;
    padding: 10px 28px;
    background: #fff;
    border: var(--border-width) solid var(--black);
    border-radius: var(--radius-button);
    cursor: pointer;
    box-shadow: var(--shadow-button);
    transition: background 0.15s, box-shadow 0.15s, transform 0.12s;
    color: var(--black);
}

.lesson-next-btn:hover {
    background: var(--primary--orange---light-active);
    box-shadow: var(--shadow-hover);
    transform: translateY(-1px);
}

.lesson-next-btn:active {
    transform: translateY(0);
    box-shadow: var(--shadow-active);
}

/* Slide transition */
.lesson-content-wrap {
    transition: opacity 0.15s ease, transform 0.15s ease;
}

.lesson-content-wrap.lesson-exit {
    opacity: 0;
    transform: translateX(-20px);
    pointer-events: none;
}

.lesson-content-wrap.lesson-enter {
    animation: lesson-enter-anim 0.2s ease forwards;
}

@keyframes lesson-enter-anim {
    from { opacity: 0; transform: translateX(20px); }
    to   { opacity: 1; transform: translateX(0); }
}

/* -------------------------------------------------------------
   DRILL VIEW
   ------------------------------------------------------------- */

.drill-container {
    max-width: 520px;
    margin: 0 auto;
    padding: 48px 24px 80px;
}

.drill-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 0 0 24px;
}

.drill-chapter-label {
    font-family: var(--font-mono);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--black50);
}

.drill-question-count {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--black50);
}

.drill-prompt {
    font-family: var(--second-family);
    font-size: var(--h6);
    font-weight: 700;
    color: var(--black);
    margin: 0 0 24px;
    line-height: 1.3;
}

.drill-tile-display {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    align-items: flex-end;
    margin: 0 0 28px;
    padding: 20px;
    background: #fff;
    border: var(--border-width) solid var(--black);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-button);
}

.drill-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin: 0 0 20px;
}

.drill-option-btn {
    font-family: var(--second-family);
    font-size: var(--paragraph);
    font-weight: 600;
    padding: 14px 18px;
    min-height: 52px;
    background: #fff;
    border: var(--border-width) solid var(--black);
    border-radius: var(--radius-card);
    cursor: pointer;
    text-align: left;
    transition: background 0.12s, border-color 0.12s, box-shadow 0.12s;
    box-shadow: var(--shadow-button);
    color: var(--black);
    line-height: 1.3;
}

.drill-option-btn:hover:not(:disabled) {
    background: var(--primary--orange---light-active);
    box-shadow: var(--shadow-hover);
}

.drill-option-btn:disabled {
    cursor: default;
}

.drill-option-btn.is-correct {
    background: #EDF7F1;
    border-color: #2A7A4F;
    color: #1B5235;
}

.drill-option-btn.is-wrong {
    background: #FEF0F0;
    border-color: var(--error);
    color: #8B1A1A;
}

.drill-feedback {
    margin: 0 0 20px;
    padding: 14px 18px;
    border-radius: var(--radius-card);
    border: var(--border-width) solid;
    font-family: var(--second-family);
    font-size: var(--paragraph);
    line-height: 1.55;
    animation: slide-up-fade 0.25s ease;
}

.drill-feedback.correct {
    border-color: #2A7A4F;
    background: #EDF7F1;
    color: #1B5235;
}

.drill-feedback.wrong {
    border-color: var(--error);
    background: #FEF0F0;
    color: #8B1A1A;
}

.drill-next-btn {
    display: block;
    width: 100%;
    font-family: var(--second-family);
    font-size: var(--paragraph);
    font-weight: 600;
    padding: 14px 18px;
    background: var(--black);
    color: #fff;
    border: var(--border-width) solid var(--black);
    border-radius: var(--radius-card);
    cursor: pointer;
    box-shadow: var(--shadow-button);
    transition: background 0.15s, box-shadow 0.15s;
    animation: slide-up-fade 0.25s ease;
}

.drill-next-btn:hover {
    background: var(--black75);
    box-shadow: var(--shadow-hover);
}

/* Drill score summary */
.drill-summary {
    text-align: center;
    padding: 48px 24px;
}

.drill-score-display {
    font-family: var(--font-family);
    font-size: var(--h1);
    font-weight: 700;
    color: var(--black);
    line-height: 1;
    margin: 0 0 8px;
}

.drill-score-denom {
    font-size: var(--h4);
    color: var(--black50);
}

.drill-score-quote {
    font-family: var(--font-family);
    font-size: var(--h5);
    font-style: italic;
    color: var(--black75);
    margin: 16px 0 36px;
}

.drill-summary-btns {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

/* -------------------------------------------------------------
   SCENARIO VIEW
   ------------------------------------------------------------- */

.scenario-container {
    max-width: 560px;
    margin: 0 auto;
    padding: 48px 24px 80px;
}

.scenario-chapter-label {
    font-family: var(--font-mono);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--black50);
    margin: 0 0 20px;
    display: block;
}

.scenario-context {
    font-family: var(--second-family);
    font-style: italic;
    font-size: var(--paragraph);
    color: var(--black50);
    margin: 0 0 8px;
    text-align: center;
    line-height: 1.5;
}

.scenario-prompt {
    font-family: var(--second-family);
    font-size: var(--h6);
    font-weight: 700;
    color: var(--black);
    margin: 0 0 24px;
    line-height: 1.35;
}

.scenario-hand-section {
    margin: 0 0 8px;
}

.scenario-discard-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 24px 0;
}

.scenario-discard-label {
    font-family: var(--font-mono);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--black50);
    display: block;
    margin-top: 10px;
}

.scenario-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 0 0 20px;
}

.scenario-option-btn {
    font-family: var(--second-family);
    font-size: var(--paragraph);
    font-weight: 600;
    padding: 16px 20px;
    min-height: 56px;
    background: #fff;
    border: var(--border-width) solid var(--black);
    border-radius: var(--radius-card);
    cursor: pointer;
    text-align: left;
    transition: background 0.12s, border-color 0.12s, box-shadow 0.12s;
    box-shadow: var(--shadow-button);
    color: var(--black);
    line-height: 1.3;
    display: flex;
    align-items: center;
    gap: 10px;
}

.scenario-option-btn:hover:not(:disabled) {
    background: var(--primary--orange---light-active);
    box-shadow: var(--shadow-hover);
}

.scenario-option-btn:disabled {
    cursor: default;
}

.scenario-option-btn.is-best {
    background: #EDF7F1;
    border-color: #2A7A4F;
    color: #1B5235;
}

.scenario-option-btn.is-wrong {
    background: #FEF0F0;
    border-color: var(--error);
    color: #8B1A1A;
}

.scenario-option-btn.is-valid {
    background: #F0F7FF;
    border-color: var(--secondary);
    color: #0D3D6B;
}

.scenario-option-icon {
    font-size: 18px;
    flex-shrink: 0;
}

.scenario-feedback {
    margin: 0 0 20px;
    padding: 14px 18px;
    border-radius: var(--radius-card);
    border: var(--border-width) solid;
    font-family: var(--second-family);
    font-size: var(--paragraph);
    line-height: 1.55;
    animation: slide-up-fade 0.25s ease;
}

.scenario-feedback.best {
    border-color: #2A7A4F;
    background: #EDF7F1;
    color: #1B5235;
}

.scenario-feedback.valid {
    border-color: var(--secondary);
    background: #F0F7FF;
    color: #0D3D6B;
}

.scenario-feedback.wrong {
    border-color: var(--error);
    background: #FEF0F0;
    color: #8B1A1A;
}

.scenario-next-btn {
    display: block;
    width: 100%;
    font-family: var(--second-family);
    font-size: var(--paragraph);
    font-weight: 600;
    padding: 14px 18px;
    background: var(--black);
    color: #fff;
    border: var(--border-width) solid var(--black);
    border-radius: var(--radius-card);
    cursor: pointer;
    box-shadow: var(--shadow-button);
    transition: background 0.15s;
    animation: slide-up-fade 0.25s ease;
}

.scenario-next-btn:hover {
    background: var(--black75);
}

/* -------------------------------------------------------------
   CHAPTER COMPLETE SCREEN
   ------------------------------------------------------------- */

.chapter-complete {
    text-align: center;
    padding: 60px 24px;
    max-width: 480px;
    margin: 0 auto;
}

.chapter-complete-icon {
    font-size: 48px;
    margin: 0 0 20px;
    display: block;
}

.chapter-complete-heading {
    font-family: var(--font-family);
    font-size: var(--h3);
    font-weight: 700;
    color: var(--black);
    margin: 0 0 12px;
}

.chapter-complete-sub {
    font-family: var(--second-family);
    font-size: var(--paragraph-larger);
    color: var(--black75);
    margin: 0 0 36px;
    line-height: 1.5;
}

.chapter-complete-btns {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

/* -------------------------------------------------------------
   CONFETTI CELEBRATION
   ------------------------------------------------------------- */

.confetti-piece {
    position: fixed;
    width: 8px;
    height: 8px;
    border-radius: 2px;
    pointer-events: none;
    z-index: 9999;
    animation: confetti-fly 1.2s ease-out forwards;
}

@keyframes confetti-fly {
    0%   { opacity: 1; transform: translate(0, 0) rotate(0deg); }
    100% { opacity: 0; transform: translate(var(--dx), var(--dy)) rotate(var(--rot)); }
}

/* -------------------------------------------------------------
   SHARED UTILITIES
   ------------------------------------------------------------- */

@keyframes slide-up-fade {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* -------------------------------------------------------------
   RESPONSIVE — MOBILE
   ------------------------------------------------------------- */

@media (max-width: 480px) {
    .mahjong-hero { font-size: var(--h3); }
    .mahjong-subtitle { font-size: var(--paragraph); margin-bottom: 32px; }
    .selector-container { padding: 36px 16px 60px; }

    .variant-card { padding: 16px; gap: 12px; }
    .variant-card-tiles { display: none; }
    .variant-name { font-size: var(--h6); }
    .variant-desc { font-size: var(--paragraph); }

    .lesson-container { padding: 32px 16px 60px; }
    .lesson-heading { font-size: var(--h5); }
    .lesson-body { font-size: var(--paragraph); }

    .drill-container { padding: 32px 16px 60px; }
    .drill-prompt { font-size: var(--paragraph-larger); }
    .drill-options { grid-template-columns: 1fr; }

    .scenario-container { padding: 32px 16px 60px; }
    .scenario-prompt { font-size: var(--paragraph-larger); }

    .tile:not(.tile-xl):not(.tile-sm) {
        width: 34px;
        height: 48px;
    }
}

/* =============================================================
   PUZZLE VIEW  (P7)
   ============================================================= */

/* Tile variants for puzzle */
.tile-md .tile-face  { width: 34px; height: 50px; }
.tile.tile-md        { width: 44px; height: 62px; }

.tile.tile-clickable {
    cursor: pointer;
    outline: none;
}
.tile.tile-clickable:hover {
    transform: translateY(-6px);
    box-shadow: 0 8px 2px #B8A48A, 0 10px 20px rgba(0,0,0,0.28);
}
.tile.tile-clickable:active {
    transform: translateY(-2px);
}
.tile.tile-highlight {
    border-color: var(--secondary--blue---default, #30B0F2);
    box-shadow: 0 4px 0 #B8A48A, 0 6px 12px rgba(48,176,242,0.35);
}

.puzzle-container {
    max-width: 640px;
    margin: 0 auto;
    padding: 24px 20px 80px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Context bar */
.puzzle-context-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}
.puzzle-ctx-tag {
    font-family: var(--font-mono);
    font-size: 11px;
    background: rgba(0,0,0,0.06);
    border-radius: 4px;
    padding: 3px 8px;
    display: flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}
.puzzle-ctx-tag .tile { margin: 0 1px; }

/* Section labels */
.puzzle-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.puzzle-section-label {
    font-family: var(--font-mono);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: rgba(0,0,0,0.45);
}
.drawn-tag {
    font-family: var(--font-mono);
    font-size: 10px;
    background: var(--secondary--blue---default, #30B0F2);
    color: #fff;
    border-radius: 3px;
    padding: 1px 5px;
    vertical-align: middle;
}

/* Rivers */
.puzzle-rivers {
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: #fff;
    border-radius: var(--radius-card, 8px);
    border: var(--border-width, 3px) solid transparent;
    padding: 12px 14px;
}
.puzzle-river-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}
.puzzle-river-label {
    font-family: var(--font-mono);
    font-size: 11px;
    color: rgba(0,0,0,0.5);
    min-width: 90px;
    flex-shrink: 0;
}
.puzzle-river-tiles {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    align-items: center;
}
.puzzle-river-empty {
    font-family: var(--font-mono);
    font-size: 13px;
    color: rgba(0,0,0,0.25);
}

/* User hand */
.puzzle-hand {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    background: #fff;
    border-radius: var(--radius-card, 8px);
    border: var(--border-width, 3px) solid transparent;
    padding: 14px;
    min-height: 82px;
    align-items: flex-end;
}

/* Hand info */
.puzzle-hand-info {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}
.hand-info-tag {
    font-family: var(--font-mono);
    font-size: 11px;
    background: rgba(0,0,0,0.06);
    border-radius: 4px;
    padding: 3px 8px;
}
.hand-info-hint {
    font-family: var(--font-mono);
    font-size: 11px;
    color: rgba(0,0,0,0.35);
    font-style: italic;
}

/* Pending discard */
.puzzle-pending-discard {
    display: flex;
    align-items: center;
    gap: 12px;
    background: #fff;
    border-radius: var(--radius-card, 8px);
    border: var(--border-width, 3px) solid var(--primary--orange---default, #F26430);
    padding: 12px 16px;
}
.puzzle-pending-label {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--primary--orange---default, #F26430);
    font-weight: 600;
}

/* Action buttons */
.puzzle-action-btns {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.puzzle-action-btn {
    font-family: var(--font-mono);
    font-size: 13px;
    padding: 10px 18px;
    border-radius: var(--radius-button, 24px);
    border: var(--border-width, 3px) solid var(--black, #1A1716);
    background: #fff;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.puzzle-action-btn:hover {
    background: var(--primary--orange---light, #FEF0EA);
}
.puzzle-action-primary {
    background: var(--black, #1A1716);
    color: #fff;
}
.puzzle-action-primary:hover {
    background: #3A3735;
    color: #fff;
}

/* Feedback */
.puzzle-feedback {
    background: #fff;
    border-radius: var(--radius-card, 8px);
    border: var(--border-width, 3px) solid transparent;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.feedback-best  { border-color: #2A7A4F; }
.feedback-ok    { border-color: var(--primary--orange---default, #F26430); }

.feedback-chosen {
    font-size: 15px;
    font-weight: 600;
}
.feedback-detail {
    font-family: var(--font-mono);
    font-size: 12px;
    color: rgba(0,0,0,0.6);
}
.feedback-best-label,
.feedback-all-label {
    font-family: var(--font-mono);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: rgba(0,0,0,0.4);
    margin-top: 6px;
}
.feedback-all-actions {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.feedback-action-row {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 6px;
    padding: 6px 8px;
    border-radius: 4px;
    background: rgba(0,0,0,0.03);
}
.feedback-action-row.is-chosen {
    background: var(--primary--orange---light, #FEF0EA);
    border-left: 3px solid var(--primary--orange---default, #F26430);
}
.feedback-rank {
    font-family: var(--font-mono);
    font-size: 11px;
    color: rgba(0,0,0,0.4);
    min-width: 24px;
}
.feedback-action-label {
    font-size: 13px;
    font-weight: 500;
}
.feedback-action-detail {
    font-family: var(--font-mono);
    font-size: 11px;
    color: rgba(0,0,0,0.5);
}
.tile.tile-dim {
    opacity: 0.3;
    pointer-events: none;
}
.chi-select-error {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--error--red---default, #F23041);
    margin-top: 6px;
    padding: 6px 10px;
    background: rgba(242,48,65,0.08);
    border-radius: 4px;
}
.puzzle-open-meld {
    display: flex;
    gap: 4px;
    margin-top: 6px;
}
.feedback-disclaimer {
    font-family: var(--font-mono);
    font-size: 10px;
    color: rgba(0,0,0,0.35);
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid rgba(0,0,0,0.08);
    font-style: italic;
    line-height: 1.4;
}

@media (max-width: 480px) {
    .puzzle-container { padding: 16px 12px 60px; }
    .puzzle-hand      { padding: 10px; gap: 3px; }
    .tile.tile-md     { width: 36px; height: 52px; }
    .tile.tile-md .tile-face { width: 28px; height: 42px; }
}

/* ─────────────────────────────────────────────────────────────
   P8 — Dead tiles panel
   ───────────────────────────────────────────────────────────── */

.dead-tiles-toggle {
    font-family: var(--font-mono);
    font-size: 11px;
    background: none;
    border: none;
    padding: 4px 0;
    cursor: pointer;
    color: rgba(0,0,0,0.45);
    letter-spacing: 0.03em;
    text-transform: uppercase;
}
.dead-tiles-toggle:hover { color: var(--black); }

.dead-tiles-panel {
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.dead-tile-group {
    display: flex;
    align-items: flex-start;
    gap: 8px;
}
.dead-tile-group-label {
    font-family: var(--font-mono);
    font-size: 10px;
    text-transform: uppercase;
    color: rgba(0,0,0,0.35);
    width: 36px;
    padding-top: 6px;
    flex-shrink: 0;
}
.dead-tile-row {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}
.dead-tile-cell {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
    position: relative;
}
.dead-tile-count {
    font-family: var(--font-mono);
    font-size: 9px;
    font-weight: 700;
    color: rgba(0,0,0,0.4);
    line-height: 1;
}
/* Tile with 0 remaining — cross it out */
.dead-tile-cell.dead-tile-gone .tile {
    opacity: 0.18;
}
.dead-tile-cell.dead-tile-gone .dead-tile-count {
    color: var(--error--red---default, #F23041);
}
/* Wait tile — highlight in blue */
.dead-tile-cell.dead-tile-wait .tile {
    box-shadow: 0 0 0 2px var(--secondary--blue---default, #30B0F2);
    border-radius: 4px;
}
.dead-tile-cell.dead-tile-wait .dead-tile-count {
    color: var(--secondary--blue---default, #30B0F2);
    font-size: 10px;
}

/* ─────────────────────────────────────────────────────────────
   P9 SKETCH — Four-sided table layout
   A CSS-only mockup; not yet wired to live data.
   Responsive: collapses to list on narrow screens.
   ───────────────────────────────────────────────────────────── */

.table-sketch {
    display: grid;
    grid-template-areas:
        ".       top     .    "
        "left    center  right"
        ".       bottom  .    ";
    grid-template-columns: 1fr 2fr 1fr;
    grid-template-rows:    auto 1fr auto;
    gap: 8px;
    max-width: 560px;
    margin: 0 auto;
    aspect-ratio: 1;
}
.table-seat              { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.table-seat-top          { grid-area: top;    flex-direction: column-reverse; }
.table-seat-left         { grid-area: left;   flex-direction: row;            justify-content: flex-end; }
.table-seat-right        { grid-area: right;  flex-direction: row; }
.table-seat-bottom       { grid-area: bottom; }
.table-center            { grid-area: center; background: rgba(0,0,0,0.04); border-radius: 8px; display: grid; grid-template-areas: "top-r" "left-r center-area right-r" "bot-r"; }
.table-seat-label        { font-family: var(--font-mono); font-size: 10px; color: rgba(0,0,0,0.4); text-transform: uppercase; }
/* Tile-count placeholders — rotated per side */
.table-tiles-h           { display: flex; gap: 2px; }
.table-tiles-v           { display: flex; flex-direction: column; gap: 2px; }
.table-tile-back         { width: 20px; height: 28px; background: #fff; border: 1.5px solid rgba(0,0,0,0.2); border-radius: 3px; }
.table-seat-right  .table-tile-back,
.table-seat-left   .table-tile-back { width: 28px; height: 20px; }
.table-seat-top    .table-tile-back { width: 20px; height: 28px; }

/* River grids inside center */
.table-river-top, .table-river-bottom { display: flex; flex-wrap: wrap; gap: 2px; justify-content: center; padding: 4px; }
.table-river-left, .table-river-right { display: flex; flex-direction: column; flex-wrap: wrap; gap: 2px; padding: 4px; }
.table-river-tile        { width: 14px; height: 20px; background: rgba(0,0,0,0.08); border-radius: 2px; }

@media (max-width: 480px) {
    /* On mobile, collapse four-sided table back to simple list */
    .table-sketch {
        display: none;
    }
    .table-sketch-fallback {
        display: block;
    }
}
.table-sketch-fallback { display: none; } /* hidden on desktop */

@media (prefers-reduced-motion: reduce) {
    .tile,
    .tile.is-interactive:hover,
    .lesson-content-wrap,
    .progress-fill {
        transition: none;
    }
    .tile.is-wrong,
    .tile.flip-in,
    .tile.bounce,
    .drill-feedback,
    .drill-next-btn,
    .scenario-feedback,
    .scenario-next-btn,
    .lesson-content-wrap.lesson-enter,
    .confetti-piece {
        animation: none;
    }
}
