/* ── Root Variables ─────────────────────────────────────────── */
:root {
  --bg-deep:     #06231a;
  --bg:          #0b3d2e;
  --felt:        #0e4a37;
  --felt-line:   #1c6a4f;
  --gold:        #d4af37;
  --gold-dim:    #8a7226;
  --gold-soft:   rgba(212,175,55,0.15);
  --ivory:       #f6ecd9;
  --ivory-edge:  #d8c79f;
  --ink:         #2a1e10;
  --danger:      #e34b4b;
  --text:        #ecebe1;
  --text-dim:    #9db8ab;
  --font-head:   'Georgia', 'Segoe UI', serif;
  --font-body:   'Segoe UI', Tahoma, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; overscroll-behavior: none; }

body {
  background: radial-gradient(ellipse 90% 60% at 50% -10%, var(--felt) 0%, var(--bg-deep) 75%);
  color: var(--text);
  font-family: var(--font-body);
  height: 100vh;
  height: 100dvh;
  user-select: none;
  overflow: hidden;
}

#app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow-y: auto; }

.screen { display: none; flex: 1; min-height: 0; flex-direction: column; padding: 1rem 0.9rem calc(0.9rem + env(safe-area-inset-bottom)); }
.screen.active { display: flex; }

/* ── Header / Menu ──────────────────────────────────────────── */
header { text-align: center; margin-bottom: 0.9rem; }

header h1 {
  font-family: var(--font-head);
  font-size: clamp(1.5rem, 6vw, 2.2rem);
  color: var(--gold);
  text-shadow: 0 0 12px rgba(212,175,55,0.35);
  letter-spacing: 0.03em;
}

header .sub { color: var(--text-dim); font-size: 0.8rem; margin-top: 0.25rem; }

.prog-wrap { max-width: 480px; width: 100%; margin: 0.4rem auto 1rem; }

.prog-bar { height: 10px; background: rgba(0,0,0,0.35); border: 1px solid var(--felt-line); border-radius: 6px; overflow: hidden; }

#progress-bar { height: 100%; background: linear-gradient(90deg, var(--gold-dim), var(--gold)); transition: width 0.3s ease; }

#progress-text { text-align: center; font-size: 0.75rem; color: var(--text-dim); margin-top: 0.4rem; letter-spacing: 0.04em; }

#level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.7rem;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

.level-card {
  background: linear-gradient(160deg, rgba(255,255,255,0.04), rgba(0,0,0,0.15)), var(--felt);
  border: 1px solid var(--felt-line);
  border-radius: 10px;
  padding: 0.9rem 0.7rem;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
}
.level-card:hover:not(.locked) { border-color: var(--gold-dim); transform: translateY(-2px); box-shadow: 0 6px 16px rgba(0,0,0,0.35); }

.level-card .lc-num { font-family: var(--font-head); font-size: 1.4rem; color: var(--gold); }
.level-card .lc-name { font-size: 0.72rem; color: var(--text-dim); margin-top: 0.15rem; }
.level-card .lc-tiles { font-size: 0.65rem; color: var(--text-dim); opacity: 0.7; margin-top: 0.1rem; }
.level-card .lc-best { font-size: 0.68rem; color: var(--gold); margin-top: 0.35rem; }

.level-card.solved { border-color: var(--gold); box-shadow: 0 0 12px rgba(212,175,55,0.25) inset; }
.level-card.locked { opacity: 0.4; cursor: default; filter: grayscale(0.6); }

/* ── Top Bar / HUD ──────────────────────────────────────────── */
#top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  margin-bottom: 0.6rem;
  flex-wrap: wrap;
}

#btn-back {
  font-family: var(--font-body);
  font-size: 0.78rem;
  background: transparent;
  border: 1px solid var(--felt-line);
  color: var(--text);
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  cursor: pointer;
}
#btn-back:hover { border-color: var(--gold-dim); color: var(--gold); }

#level-info { text-align: center; flex: 1; min-width: 100px; }
#level-title { display: block; font-family: var(--font-head); font-size: 1rem; color: var(--gold); }
#level-meta { display: block; font-size: 0.65rem; color: var(--text-dim); }

#timer { font-variant-numeric: tabular-nums; font-size: 0.85rem; color: var(--text); background: rgba(0,0,0,0.25); border: 1px solid var(--felt-line); border-radius: 6px; padding: 0.35rem 0.6rem; }

.hud {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  background: rgba(0,0,0,0.25);
  border: 1px solid var(--felt-line);
  border-radius: 8px;
  padding: 0.5rem 0.7rem;
  margin-bottom: 0.7rem;
  flex-wrap: wrap;
}

.hud-segment { display: flex; flex-direction: column; align-items: center; min-width: 50px; }
.hud-label { font-size: 0.55rem; letter-spacing: 0.14em; color: var(--text-dim); }
.hud-value { font-family: var(--font-head); font-size: 1.15rem; color: var(--gold); line-height: 1; }

.tool-btn {
  width: 38px; height: 38px;
  background: transparent;
  border: 1px solid var(--felt-line);
  border-radius: 8px;
  color: var(--text);
  font-size: 1.05rem;
  cursor: pointer;
  transition: all 0.15s;
  display: flex; align-items: center; justify-content: center;
}
.tool-btn:hover { border-color: var(--gold-dim); background: var(--gold-soft); }
.tool-btn:active { transform: scale(0.92); }
.tool-btn:disabled { opacity: 0.3; cursor: default; }

#hint-message {
  text-align: center;
  min-height: 1.2rem;
  font-size: 0.75rem;
  color: var(--gold);
  margin-top: 0.5rem;
}

/* ── Board ──────────────────────────────────────────────────── */
#board-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

#game-board {
  position: relative;
  transform-origin: center center;
}

.tile {
  position: absolute;
  border-radius: 6px;
  background: linear-gradient(160deg, #fffdf6, var(--ivory) 55%, #e9dcc0);
  border: 1px solid var(--ivory-edge);
  box-shadow:
    2px 2px 0 #c9b78c,
    3px 3px 0 #a8936a,
    0 3px 6px rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.1rem;
  line-height: 1;
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.15s;
  user-select: none;
}

.tile.blocked {
  filter: brightness(0.62) saturate(0.7);
  cursor: default;
}

.tile.free:hover {
  transform: translateY(-2px);
  box-shadow:
    2px 4px 0 #c9b78c,
    3px 6px 0 #a8936a,
    0 6px 10px rgba(0,0,0,0.5);
}

.tile.selected {
  border-color: var(--gold);
  box-shadow:
    0 0 0 2px var(--gold),
    2px 2px 0 #c9b78c,
    3px 3px 0 #a8936a,
    0 0 14px rgba(212,175,55,0.7);
  transform: translateY(-3px);
}

.tile.hint {
  animation: hint-pulse 0.55s ease-in-out 2;
}

.tile.mismatch {
  animation: shake 0.35s ease-in-out;
}

.tile.matched {
  animation: tile-pop 0.28s ease-in forwards;
  pointer-events: none;
}

.tile .glyph { pointer-events: none; transform: scale(1.35); }

.suit-dragon.tile[data-glyph="🀄"] .glyph { color: #b5182a; }
.suit-dragon.tile[data-glyph="🀅"] .glyph { color: #16794a; }

@keyframes hint-pulse {
  0%, 100% { box-shadow: 0 0 0 2px var(--gold), 2px 2px 0 #c9b78c, 3px 3px 0 #a8936a, 0 0 8px rgba(212,175,55,0.5); }
  50% { box-shadow: 0 0 0 2px var(--gold), 2px 2px 0 #c9b78c, 3px 3px 0 #a8936a, 0 0 22px rgba(212,175,55,0.95); }
}

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

@keyframes tile-pop {
  0% { transform: scale(1); opacity: 1; }
  100% { transform: scale(0.4); opacity: 0; }
}

/* ── Gewinn-Screen ──────────────────────────────────────────── */
#screen-win { align-items: center; justify-content: center; }

#win-box {
  background: var(--felt);
  border: 1px solid var(--gold-dim);
  border-radius: 14px;
  padding: 2rem 1.8rem;
  max-width: 360px;
  width: 100%;
  text-align: center;
  box-shadow: 0 0 40px rgba(212,175,55,0.2);
}

#win-icon { font-size: 3rem; margin-bottom: 0.4rem; }
#win-box h2 { font-family: var(--font-head); color: var(--gold); margin-bottom: 0.5rem; }
#win-stats { color: var(--text); font-size: 0.9rem; margin-bottom: 0.2rem; }
#win-stars { font-size: 1.2rem; margin-bottom: 1.2rem; }

#win-btns { display: flex; gap: 0.6rem; justify-content: center; flex-wrap: wrap; }

#win-btns button, #resume-modal-btns button {
  font-family: var(--font-body);
  font-size: 0.82rem;
  background: transparent;
  border: 1px solid var(--gold-dim);
  color: var(--gold);
  padding: 0.55rem 1.1rem;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
}
#win-btns button:hover, #resume-modal-btns button:hover { background: var(--gold-soft); box-shadow: 0 0 12px rgba(212,175,55,0.3); }

/* ── Resume-Modal ───────────────────────────────────────────── */
#resume-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 30;
  padding: 16px;
}
#resume-modal-overlay.active { display: flex; }

#resume-modal {
  background: var(--felt);
  border: 1px solid var(--gold-dim);
  border-radius: 14px;
  padding: 1.8rem 1.6rem;
  max-width: 360px;
  width: 100%;
  text-align: center;
  box-shadow: 0 0 40px rgba(212,175,55,0.2);
}
#resume-modal-icon { font-size: 2.4rem; margin-bottom: 0.4rem; }
#resume-modal h2 { font-family: var(--font-head); color: var(--gold); margin-bottom: 0.6rem; }
#resume-modal-body { color: var(--text-dim); font-size: 0.82rem; line-height: 1.5; margin-bottom: 1.2rem; }
#resume-modal-btns { display: flex; gap: 0.6rem; justify-content: center; flex-wrap: wrap; }

@media (min-width: 700px) {
  header h1 { font-size: 2.4rem; }
}
