@font-face {
  font-family: 'Aksara';
  src: url('../fonts/nykngayogyannew.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

:root {
  --cream: #F0EAD9;
  --paper: #FBF8F1;
  --ink: #1C1A16;
  --terracotta: #B5502E;
  --terracotta-soft: #E7B7A2;
  --teal: #3E7C74;
  --teal-soft: #CFE7E2;
  --teal-side: #9BC4BC;
  --gold: #9C7A3C;
  --gold-soft: #F1E3C2;
  --gold-side: #D9BE85;
  --muted: #8A8574;
  --line: #1C1A16;
  --tile-size: 46px;
  --layer-shift: 8px;
}

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

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--cream);
  background-image: radial-gradient(circle at 1px 1px, rgba(28, 26, 22, 0.09) 1px, transparent 0);
  background-size: 20px 20px;
  color: var(--ink);
  font-family: 'Space Mono', monospace;
  min-height: 100%;
  overscroll-behavior: none;
}

body.is-playing {
  height: 100dvh;
  overflow: hidden;
}

.page {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 28px 16px 56px;
}

body.is-playing .page {
  max-width: none;
  height: 100dvh;
  padding: 10px;
  display: flex;
}

.panel {
  background: var(--paper);
  border: 2px solid var(--line);
  box-shadow: 6px 6px 0 rgba(28, 26, 22, 0.9);
  padding: 22px 20px;
}

.play-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 12px 12px 14px;
  width: 100%;
}

.hidden {
  display: none !important;
}

.brand-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 6px;
}

.brand {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  font-size: 30px;
  line-height: 0.92;
  letter-spacing: -0.5px;
}

.brand .dash {
  color: var(--terracotta);
}

.tagline {
  color: var(--muted);
  font-size: 13px;
  margin: 4px 0 22px;
}

.difficulty-grid {
  display: grid;
  gap: 14px;
}

.difficulty-card {
  text-align: left;
  background: var(--paper);
  border: 2px solid var(--line);
  box-shadow: 4px 4px 0 rgba(28, 26, 22, 0.9);
  padding: 16px;
  cursor: pointer;
  font-family: inherit;
  color: var(--ink);
  transition: transform 0.12s ease;
}

.difficulty-card:hover {
  transform: translate(-2px, -2px);
  box-shadow: 6px 6px 0 rgba(28, 26, 22, 0.9);
}

.difficulty-title {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  font-size: 19px;
}

.difficulty-tagline {
  color: var(--muted);
  font-size: 12.5px;
  margin-top: 4px;
}

.difficulty-sample {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.sample-aksara {
  font-family: 'Aksara', sans-serif;
  font-size: 22px;
  background: var(--teal-soft);
  border: 2px solid var(--line);
  padding: 2px 8px;
}

.sample-latin {
  background: var(--gold-soft);
  border: 2px solid var(--line);
  padding: 3px 8px;
  font-weight: 700;
}

.sample-arrow {
  color: var(--muted);
}

.how-to {
  margin-top: 20px;
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.5;
  border-top: 2px dashed var(--muted);
  padding-top: 14px;
}

.play-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.level-name {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  font-size: 18px;
}

.stat-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.stat-box {
  border: 2px solid var(--line);
  background: var(--paper);
  box-shadow: 3px 3px 0 rgba(28, 26, 22, 0.9);
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.stat-label {
  color: var(--muted);
  font-weight: 400;
  margin-right: 4px;
}

.board-wrapper {
  flex: 1;
  min-height: 0;
  margin: 10px 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.board-scaler {
  position: relative;
}

.board {
  position: relative;
}

.tile {
  position: absolute;
  width: var(--tile-size);
  height: calc(var(--tile-size) * 1.3);
  border: none;
  border-radius: 3px;
  display: block;
  font-family: inherit;
  cursor: default;
  padding: 0;
  overflow: visible;
  background: none;
  -webkit-appearance: none;
  appearance: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.tile-face {
  position: absolute;
  inset: 0;
  border-radius: 3px;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background-color: #F5F0EB;
  padding: 5% 8%;
  box-shadow:
    inset -2px -2px 5px 1px #b5b5aabb,
    inset 2px 2px 3px 1px #f9f4f0,
    1px 1px 0 1px #bfbab4,
    2px 2px 0 1px #bfbab4,
    3px 3px 0 1px var(--tile-edge, #b5b5aa),
    var(--layer-shadow, 3px 4px 6px 1px rgba(0, 0, 0, 0.3));
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.tile-aksara .tile-face { --tile-edge: #6f9c93; }
.tile-latin .tile-face { --tile-edge: #b98861; }

.tile-face::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, #D9C79A 0%, #C9B584 50%, #D9C79A 100%);
  border-radius: 3px 3px 0 0;
}

.tile.is-peeking .tile-face {
  transform: scale(1.35) translateY(-4px);
  box-shadow:
    inset -2px -2px 5px 1px #b5b5aabb,
    inset 2px 2px 3px 1px #f9f4f0,
    1px 1px 0 1px #bfbab4,
    2px 2px 0 1px #bfbab4,
    3px 3px 0 1px var(--tile-edge, #b5b5aa),
    0 12px 24px rgba(20, 16, 8, 0.55);
  outline: 2px solid var(--gold);
  outline-offset: -2px;
}

.tile.layer-0 { --layer-shadow: 3px 4px 6px 1px rgba(0, 0, 0, 0.28); }
.tile.layer-1 { --layer-shadow: 4px 5px 7px 1px rgba(0, 0, 0, 0.32); }
.tile.layer-2 { --layer-shadow: 4px 6px 8px 2px rgba(0, 0, 0, 0.36); }
.tile.layer-3 { --layer-shadow: 5px 7px 9px 2px rgba(0, 0, 0, 0.4); }
.tile.layer-4 { --layer-shadow: 5px 8px 10px 2px rgba(0, 0, 0, 0.44); }

.tile-glyph {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  flex: 1;
  min-height: 0;
  line-height: 1;
  font-weight: 700;
}

.tile-aksara .tile-glyph {
  font-family: 'Aksara', sans-serif;
  color: var(--teal);
}

.tile-aksara .tile-glyph span {
  display: inline-block;
  line-height: 1;
  transform: translateY(12%);
  white-space: nowrap;
}

.tile-latin .tile-glyph {
  font-family: 'Space Grotesk', sans-serif;
  text-transform: lowercase;
  color: var(--terracotta);
}

.tile-latin .tile-glyph span {
  display: inline-block;
  line-height: 1;
  white-space: nowrap;
}

.tile-gloss {
  font-size: 6.5px;
  color: var(--ink);
  opacity: 0.55;
  margin-top: 2%;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  flex-shrink: 0;
  white-space: nowrap;
  max-width: 100%;
  line-height: 1.15;
  text-align: center;
}

.tile.is-locked .tile-face {
  filter: grayscale(0.6) brightness(0.85);
}

.tile.is-locked {
  cursor: not-allowed;
}

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

.tile.is-open:hover .tile-face {
  transform: translate(-1px, -2px);
}

.tile.is-selected .tile-face {
  outline: 3px solid var(--terracotta);
  outline-offset: -2px;
}

.tile.is-mismatch .tile-face {
  animation: shake 0.4s ease;
  background: var(--terracotta-soft) !important;
}

.tile.is-hint .tile-face {
  animation: pulseGlow 0.7s ease infinite;
}

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

@keyframes pulseGlow {
  0%, 100% { outline: 3px solid var(--gold); outline-offset: -2px; }
  50% { outline: 3px solid transparent; outline-offset: -2px; }
}

.action-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.action-btn {
  flex: 1;
  min-width: 90px;
  border: 2px solid var(--line);
  background: var(--paper);
  box-shadow: 3px 3px 0 rgba(28, 26, 22, 0.9);
  padding: 10px 8px;
  font-family: 'Space Mono', monospace;
  font-weight: 700;
  font-size: 12px;
  cursor: pointer;
  color: var(--ink);
}

.action-btn:hover {
  transform: translate(-1px, -1px);
  box-shadow: 4px 4px 0 rgba(28, 26, 22, 0.9);
}

.action-btn.ghost {
  background: transparent;
}

.toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translate(-50%, 20px);
  background: var(--ink);
  color: var(--paper);
  padding: 10px 16px;
  border: 2px solid var(--line);
  font-size: 12.5px;
  opacity: 0;
  transition: all 0.2s ease;
  pointer-events: none;
  max-width: 90%;
  text-align: center;
  z-index: 1200;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(28, 26, 22, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 999;
}

.modal {
  background: var(--paper);
  border: 2px solid var(--line);
  box-shadow: 6px 6px 0 rgba(28, 26, 22, 0.9);
  padding: 24px;
  width: 100%;
  max-width: 360px;
}

.modal h2 {
  font-family: 'Space Grotesk', sans-serif;
  margin: 0 0 4px;
}

.modal-sub {
  color: var(--muted);
  font-size: 12.5px;
  margin-bottom: 16px;
}

.result-rows {
  display: grid;
  gap: 8px;
  margin-bottom: 18px;
}

.result-row {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px dashed var(--muted);
  padding-bottom: 6px;
  font-size: 13px;
}

.result-row b {
  font-family: 'Space Grotesk', sans-serif;
}

.modal-actions {
  display: flex;
  gap: 10px;
}

@media (min-width: 480px) {
  .difficulty-grid {
    grid-template-columns: repeat(1, 1fr);
  }
}

@media (max-width: 480px) {
  body.is-playing .page {
    padding: 6px;
  }
  .play-panel {
    padding: 8px 8px 10px;
  }
  .level-name {
    font-size: 15px;
  }
  .stat-box {
    font-size: 10.5px;
    padding: 4px 7px;
  }
  .action-btn {
    font-size: 11px;
    padding: 9px 6px;
    min-width: 70px;
  }
}
