/* ── CSS Custom Properties ── */
:root {
    --bg:        #110800;
    --bg2:       #1e0f00;
    --gold:      #f5c842;
    --gold-dim:  #c9992a;
    --gold-glow: #ffe680;
    --amber:     #e07b10;
    --red:       #e03030;
    --green:     #34c66b;
    --text:      #f0ddb0;
    --text-dim:  #9c7a45;
    --cell-bg:   #2a1500;
    --cell-bdr:  #5c3510;
    --slot-bg:   #180c00;
    --slot-fill: #2e1800;
    --radius:    10px;
    --font-h:    'Cinzel Decorative', serif;
    --font-b:    'Barlow', sans-serif;
    --tap-min:   44px;
  }

  /* ── Reset ── */
  *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
  html, body { height: 100%; overscroll-behavior: none; }
  body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-b);
    font-size: 15px;
    line-height: 1.4;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100dvh;
    padding: 0 0 env(safe-area-inset-bottom);
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }

  /* ── Background texture ── */
  body::before {
    content: '';
    position: fixed; inset: 0;
    background:
      radial-gradient(ellipse 80% 60% at 50% 0%, #3d1a0080 0%, transparent 70%),
      repeating-linear-gradient(0deg, transparent 0px, transparent 39px, #ffffff04 40px),
      repeating-linear-gradient(90deg, transparent 0px, transparent 39px, #ffffff03 40px);
    pointer-events: none; z-index: 0;
  }

  /* ── Layout ── */
  #app {
    position: relative; z-index: 1;
    width: 100%; max-width: 420px;
    padding: 16px 14px 24px;
    display: flex; flex-direction: column; align-items: center; gap: 14px;
  }

  /* ── Header ── */
  header { text-align: center; width: 100%; }
  header h1 {
    font-family: var(--font-h);
    font-size: clamp(18px, 5.5vw, 26px);
    color: var(--gold);
    text-shadow: 0 0 18px #f5c84260, 0 2px 4px #000;
    letter-spacing: .05em;
    line-height: 1.2;
  }
  header p {
    font-size: 12px;
    color: var(--text-dim);
    letter-spacing: .15em;
    text-transform: uppercase;
    margin-top: 3px;
  }

  /* ── Divider ── */
  .divider {
    width: 100%;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--gold-dim), transparent);
    opacity: .5;
  }

  /* ── Chest SVG ── */
  #chest-wrap {
    position: relative;
    display: flex; flex-direction: column; align-items: center;
    width: 100%;
    margin-top: -10px;
  }
  #chest-svg {
    width: clamp(110px, 35vw, 150px);
    height: auto;
    filter: drop-shadow(0 4px 18px #f5c84230);
    transition: filter .4s;
  }
  #chest-svg.open { filter: drop-shadow(0 0 28px #f5c84290) drop-shadow(0 0 8px #fff5); }

  /* Chest lid animates open */
  #chest-lid {
    transform-origin: 50% 100%;
    transition: transform .5s cubic-bezier(.34,1.56,.64,1);
  }
  #chest-svg.open #chest-lid { transform: rotate(-115deg) translateY(-2px); }

  /* ── Password Display ── */
  #password-label {
    font-size: 11px;
    color: var(--text-dim);
    letter-spacing: .2em;
    text-transform: uppercase;
    margin-top: 4px;
  }
  #password-display {
    display: flex; gap: 6px; margin-top: 6px;
    justify-content: center;
  }
  .pwd-char {
    display: flex; align-items: center; justify-content: center;
    min-width: 34px; height: 38px;
    background: linear-gradient(160deg, #3d2200, #1e1000);
    border: 1.5px solid var(--gold-dim);
    border-radius: 6px;
    font-family: var(--font-h);
    font-size: 17px;
    color: var(--gold-glow);
    letter-spacing: .05em;
    box-shadow: inset 0 1px 0 #ffffff15, 0 2px 6px #00000060;
    text-shadow: 0 0 8px #ffe68080;
  }

  /* ── Attempt Slots ── */
  #slots-label {
    font-size: 11px;
    color: var(--text-dim);
    letter-spacing: .2em;
    text-transform: uppercase;
    align-self: flex-start;
    padding-left: 2px;
  }
  #slots {
    display: flex; gap: 6px; width: 100%; justify-content: center;
  }
  .slot {
    flex: 1;
    min-width: 44px; max-width: 56px; height: 52px;
    display: flex; align-items: center; justify-content: center;
    background: var(--slot-bg);
    border: 2px solid var(--cell-bdr);
    border-radius: 8px;
    font-family: var(--font-h);
    font-size: 20px;
    color: var(--gold);
    transition: background .2s, border-color .2s, transform .15s;
    position: relative;
    overflow: hidden;
  }
  .slot.filled { background: var(--slot-fill); border-color: var(--gold-dim); }
  .slot.correct {
    background: #0d2e1a;
    border-color: var(--green);
    color: var(--green);
    box-shadow: 0 0 10px #34c66b50;
  }
  .slot.wrong {
    background: #2e0d0d;
    border-color: var(--red);
    color: var(--red);
    box-shadow: 0 0 10px #e0303050;
  }
  .slot.shake { animation: shake .3s ease; }

  @keyframes shake {
    0%,100%{ transform: translateX(0); }
    25%{ transform: translateX(-5px); }
    75%{ transform: translateX(5px); }
  }

  /* ── Action Buttons ── */
  #actions {
    display: flex; gap: 10px; width: 100%;
  }
  .btn {
    flex: 1; height: var(--tap-min);
    border: none; border-radius: 8px;
    font-family: var(--font-b); font-size: 14px; font-weight: 600;
    cursor: pointer;
    letter-spacing: .05em;
    transition: opacity .15s, transform .1s;
    -webkit-tap-highlight-color: transparent;
  }
  .btn:active { transform: scale(.96); opacity: .85; }

  #btn-clear {
    background: linear-gradient(160deg, #3a1a00, #240f00);
    color: var(--text-dim);
    border: 1.5px solid var(--cell-bdr);
  }
  #btn-unlock {
    background: linear-gradient(160deg, #c98a10, #7a4e05);
    color: #fff8e8;
    border: 1.5px solid var(--gold);
    box-shadow: 0 2px 12px #f5c84240;
    font-weight: 700;
    letter-spacing: .08em;
  }
  #btn-unlock:disabled {
    opacity: .4; cursor: default;
    box-shadow: none;
  }

  /* ── Status Message ── */
  #status {
    min-height: 22px;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: .04em;
    text-align: center;
    transition: opacity .3s;
  }
  #status.success { color: var(--green); }
  #status.fail    { color: var(--red); }
  #status.info    { color: var(--gold-dim); }

  /* ── Points Bar ── */
  #points-bar {
    display: flex; align-items: center; gap: 8px;
    width: 100%;
    background: var(--bg2);
    border: 1px solid var(--cell-bdr);
    border-radius: 8px;
    padding: 11px 14px;
  }
  #points-bar span { font-size: 13px; color: var(--text-dim); }
  #points-val {
    font-family: var(--font-h);
    font-size: 16px; color: var(--gold);
    margin-left: auto;
  }
  #attempts-left { font-size: 12px; color: var(--text-dim); }

  /* ── Grid Section ── */
  .grid-section { width: 100%; }
  .grid-title {
    font-size: 11px;
    color: var(--text-dim);
    letter-spacing: .2em;
    text-transform: uppercase;
    margin-bottom: 7px;
  }
  .char-grid {
    display: grid;
    gap: 5px;
  }
  #letters-grid { grid-template-columns: repeat(9, 1fr); }
  #digits-grid  { grid-template-columns: repeat(10, 1fr); }

  .cell {
    aspect-ratio: 1;
    min-width: 0;
    min-height: 40px;
    display: flex; align-items: center; justify-content: center;
    background: var(--cell-bg);
    border: 1.5px solid var(--cell-bdr);
    border-radius: 6px;
    font-family: var(--font-b);
    font-size: clamp(13px, 3.5vw, 16px);
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
    transition: background .12s, border-color .12s, transform .1s, color .12s;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
  }
  .cell:active  { transform: scale(.9); }
  .cell.active  {
    background: linear-gradient(160deg, #5c3200, #3a1e00);
    border-color: var(--gold);
    color: var(--gold-glow);
    box-shadow: 0 0 8px #f5c84230;
  }
  .cell.used    { opacity: .3; pointer-events: none; }

  /* ── Win Overlay ── */
  #win-overlay {
    display: none;
    position: fixed; inset: 0; z-index: 100;
    background: #00000090;
    align-items: center; justify-content: center;
    backdrop-filter: blur(3px);
  }
  #win-overlay.show { display: flex; animation: fadeIn .4s ease; }
  #win-card {
    background: linear-gradient(170deg, #2a1400, #110800);
    border: 2px solid var(--gold);
    border-radius: 18px;
    padding: 32px 28px;
    max-width: 340px; width: 90%;
    text-align: center;
    box-shadow: 0 0 60px #f5c84240;
    animation: popIn .4s cubic-bezier(.34,1.56,.64,1);
  }
  #win-card h2 {
    font-family: var(--font-h);
    font-size: 22px; color: var(--gold);
    text-shadow: 0 0 18px #f5c84260;
    margin-bottom: 10px;
  }
  #win-card p  { font-size: 15px; color: var(--text); margin-bottom: 6px; }
  #win-pts     { font-family: var(--font-h); font-size: 28px; color: var(--gold-glow); }
  #btn-play-again {
    margin-top: 20px;
    width: 100%; height: 48px;
    background: linear-gradient(160deg, #c98a10, #7a4e05);
    border: 1.5px solid var(--gold);
    border-radius: 10px;
    color: #fff8e8; font-family: var(--font-b); font-size: 15px; font-weight: 700;
    cursor: pointer; letter-spacing: .08em;
  }

  /* Coins burst */
  .coin {
    position: fixed;
    width: 12px; height: 12px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 35%, #ffe680, #c98a10);
    pointer-events: none;
    z-index: 110;
    animation: coinBurst var(--dur) ease-out forwards;
  }



  .slot {
    position: relative;
  }
  
  .slot-icon {
    position: absolute;
    bottom: 4px;
    right: 6px;
    font-size: 12px;
    font-weight: bold;
  }
  
  .slot.correct {
    background: #22c55e;
    color: white;
    border-color: #22c55e;
  }
  
  .slot.wrong {
    background: #ef4444;
    color: white;
    border-color: #ef4444;
  }


  @keyframes coinBurst {
    0%   { transform: translate(0,0) scale(1); opacity: 1; }
    100% { transform: translate(var(--tx), var(--ty)) scale(.3); opacity: 0; }
  }

  @keyframes fadeIn  { from { opacity: 0; } to { opacity: 1; } }
  @keyframes popIn   {
    from { transform: scale(.7) translateY(30px); opacity: 0; }
    to   { transform: scale(1) translateY(0);     opacity: 1; }
  }