 :root{
    --page-bg: #14160f;
    --table-green: #1f4d3d;
    --table-green-dark: #163a2d;
    --tile-face: #fbf3e1;
    --tile-face-edge: #e3d4ab;
    --tile-ink: #2b2b2b;
    --tile-red: #a8362a;
    --tile-jade: #2f7d52;
    --tile-blue: #2c4a6e;
    --gold: #c9a227;
    --wood: #5b3a22;
    --wood-light: #7c5331;
    --paper: #f4ecd8;
    --paper-edge: #d9c79e;
    --text-light: #f4f1ea;
    --text-dim: #cfd8c9;
  }
  *{ box-sizing: border-box; }
  html,body{ margin:0; padding:0; }
  body{
    background: var(--page-bg);
    background-image: radial-gradient(circle at 50% 0%, #1d2118 0%, #14160f 60%);
    color: var(--text-light);
    font-family: 'Noto Sans TC', sans-serif;
    min-height: 100vh;
    display:flex;
    justify-content:center;
    padding: 22px 12px 60px;
  }
  .app{ width:100%; max-width: 920px; }

  .frame{
    border: 10px solid var(--wood);
    border-radius: 18px;
    background: linear-gradient(180deg, var(--wood-light), var(--wood));
    padding: 8px;
    box-shadow: 0 18px 40px rgba(0,0,0,0.45);
  }
  .table{
    background:
      radial-gradient(circle at 20% 10%, rgba(255,255,255,0.05), transparent 40%),
      linear-gradient(160deg, var(--table-green), var(--table-green-dark));
    border-radius: 12px;
    padding: 16px 16px 20px;
  }

  header{
    display:flex; align-items:center; justify-content:space-between;
    flex-wrap: wrap; gap: 8px;
    padding-bottom: 10px;
    margin-bottom: 12px;
    border-bottom: 1px solid rgba(244,241,234,0.18);
  }
  header h1{
    font-family:'Noto Serif TC', serif;
    font-weight:900;
    font-size: clamp(1.15rem, 4vw, 1.5rem);
    margin:0;
    letter-spacing: 2px;
    color: var(--text-light);
  }
  header h1 span{ color: var(--gold); }
  .score{
    font-size: 0.85rem;
    color: var(--text-dim);
    background: rgba(0,0,0,0.22);
    border-radius: 999px;
    padding: 6px 14px;
    display:flex; gap:12px;
  }
  .score b{ color: var(--text-light); font-weight:700; }
  .info-toggle{
    background:none; border:1px solid rgba(244,241,234,0.4);
    color:var(--text-light); border-radius:999px; width:26px;height:26px;
    cursor:pointer; font-weight:700; font-family:'Noto Serif TC',serif;
  }
  .info-toggle:hover{ background: rgba(244,241,234,0.12); }

  .info-panel{
    display:none;
    background: var(--paper);
    color:#3a3326;
    border: 1px solid var(--paper-edge);
    border-radius: 10px;
    padding: 12px 14px;
    font-size: 0.85rem;
    line-height:1.6;
    margin-bottom: 14px;
  }
  .info-panel.open{ display:block; }

  .opponent-zone{ text-align:center; margin-bottom: 14px; }
  .zone-label{
    font-size: 0.78rem; color: var(--text-dim); margin-bottom:6px;
    letter-spacing: 1px;
  }
  .tile-row{
    display:flex; flex-wrap:wrap; justify-content:center; gap:5px;
  }

  .tile{
    width: 38px; height: 54px;
    background: linear-gradient(180deg, var(--tile-face), #f1e6c8);
    border: 1px solid var(--tile-face-edge);
    border-radius: 6px;
    display:flex; align-items:center; justify-content:center;
    font-family:'Noto Serif TC', serif;
    font-weight:700;
    font-size: 1.05rem;
    color: var(--tile-ink);
    box-shadow: 0 2px 0 #c9b988, 0 4px 6px rgba(0,0,0,0.35);
    user-select:none;
    position:relative;
  }
  .tile.wind{ color: var(--tile-blue); }
  .tile.dragon-red{ color: var(--tile-red); }
  .tile.dragon-green{ color: var(--tile-jade); }
  .tile.dragon-white{
    color: rgba(43,43,43,0.35);
    font-size:0.85rem;
  }
  .tile.dragon-white::before{
    content:'';
    position:absolute; inset:7px;
    border: 1.5px solid rgba(43,43,43,0.35);
    border-radius:2px;
  }
  .tile.back{
    background: linear-gradient(160deg, #2f6650, #1f4d3d);
    border: 1px solid #14352a;
    box-shadow: 0 2px 0 #123226, 0 4px 6px rgba(0,0,0,0.35);
  }
  .tile.back::after{
    content:'';
    position:absolute; inset:6px;
    border: 1px solid rgba(244,241,234,0.18);
    border-radius:3px;
  }
  .tile.clickable{ cursor:pointer; transition: transform .15s ease, box-shadow .15s ease; }
  .tile.clickable:hover, .tile.clickable:focus-visible{
    transform: translateY(-6px);
    box-shadow: 0 8px 0 #c9b988, 0 12px 14px rgba(0,0,0,0.4);
    outline: none;
  }
  .tile.clickable:focus-visible{ outline: 2px solid var(--gold); outline-offset:2px; }
  .tile.discarded{
    width:30px; height:42px; font-size:0.85rem;
    opacity:0.92;
  }
  .tile.new{
    box-shadow: 0 0 0 2px var(--gold), 0 4px 6px rgba(0,0,0,0.35);
  }

  .mid-zone{
    display:grid;
    grid-template-columns: 1.6fr 1fr;
    gap: 12px;
    margin-bottom: 14px;
  }
  @media (max-width: 600px){
    .mid-zone{ grid-template-columns: 1fr; }
  }
  .board-info{
    background: rgba(0,0,0,0.2);
    border-radius: 10px;
    padding: 10px 12px;
  }
  .status-line{
    font-size:0.82rem; color: var(--text-dim);
    display:flex; flex-wrap:wrap; gap: 10px 16px;
    margin-bottom: 10px;
  }
  .status-line b{ color: var(--text-light); }
  .discard-row{ margin-bottom: 8px; }
  .discard-row .zone-label{ text-align:left; margin-bottom:4px; }
  .discard-tiles{
    display:flex; flex-wrap:wrap; gap:4px;
    min-height: 46px;
    max-height: 96px; overflow-y:auto;
    padding: 2px;
  }

  .log-panel{
    background: var(--paper);
    color:#3a3326;
    border-radius:10px;
    padding: 10px 12px;
    font-size: 0.78rem;
    line-height:1.5;
    max-height: 168px;
    overflow-y:auto;
  }
  .log-panel .zone-label{ color:#7a6a45; text-align:left; }
  .log-panel div.line{ margin-bottom:3px; }

  .player-zone{ text-align:center; }
  .hand-row{
    display:flex; flex-wrap:wrap; justify-content:center; gap:5px;
    margin-bottom: 10px;
    min-height: 64px;
  }
  .hint{
    font-size:0.85rem; color: var(--gold);
    min-height: 1.2em;
    margin-bottom: 8px;
  }

  .actions{ text-align:center; margin-top: 6px; }
  .btn{
    font-family:'Noto Sans TC', sans-serif;
    font-weight:700;
    font-size:0.9rem;
    padding: 9px 22px;
    border-radius: 999px;
    border: none;
    cursor:pointer;
    background: var(--gold);
    color: #2b2106;
    transition: transform .12s ease, filter .12s ease;
  }
  .btn:hover{ filter: brightness(1.08); transform: translateY(-1px); }
  .btn:focus-visible{ outline: 2px solid var(--text-light); outline-offset:2px; }
  .btn.secondary{
    background: transparent;
    color: var(--text-light);
    border: 1px solid rgba(244,241,234,0.5);
  }

  .overlay{
    position: fixed; inset:0;
    background: rgba(10,12,8,0.78);
    display:none;
    align-items:center; justify-content:center;
    padding: 16px;
    z-index: 50;
  }
  .overlay.open{ display:flex; }
  .result-card{
    background: var(--paper);
    color:#3a3326;
    border-radius: 14px;
    max-width: 560px; width:100%;
    padding: 22px 22px 18px;
    box-shadow: 0 24px 60px rgba(0,0,0,0.5);
    max-height: 88vh; overflow-y:auto;
  }
  .result-card h2{
    font-family:'Noto Serif TC', serif;
    font-size: 1.6rem;
    margin: 0 0 4px;
  }
  .result-card .method{
    color:#7a6a45; font-size:0.95rem; margin-bottom:14px;
  }
  .reveal-block{ margin-bottom: 12px; }
  .reveal-block .who{ font-size:0.8rem; font-weight:700; color:#7a6a45; margin-bottom:4px; }
  .reveal-tiles{ display:flex; flex-wrap:wrap; gap:4px; }
  .result-actions{ text-align:center; margin-top: 16px; }

  @media (prefers-reduced-motion: reduce){
    .tile.clickable, .btn{ transition:none; }
  }

  footer{
    text-align:center; color: var(--text-dim);
    font-size: 0.72rem; margin-top: 14px;
  }