/* Arrow Escape Grid · stylesheet
   Minimalist Ellgame UI with a clean white board and navy arrows.
   Everything outside the canvas: shell, drawer, modals, controls. */

:root {
  --bg:          #ffffff;
  --bg-soft:     #f4f6ff;
  --ink:         #0d1d39;
  --ink-soft:    #65718a;
  --ink-faint:   #a8b0c3;
  --line:        #e3e8f7;
  --line-strong: #c7d0ea;
  --accent:      #4d63f6;
  --danger:      #d94747;
  --heart:       #e7505b;
  --hint:        #4d63f6;
  --good:        #1f9f68;
  --shadow:      0 10px 28px rgba(45,62,128,.12), 0 2px 4px rgba(31,42,84,.06);
  --radius:      14px;
  --radius-sm:   8px;
  --t-fast:      120ms;
  --t-med:       240ms;
  --t-slow:      420ms;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

:root.dark {
  --bg:          #f7f9ff;
  --bg-soft:     #eef2ff;
  --ink:         #0d1d39;
  --ink-soft:    #65718a;
  --ink-faint:   #a8b0c3;
  --line:        #dfe6fb;
  --line-strong: #c7d0ea;
  --accent:      #4d63f6;
  --danger:      #d94747;
  --heart:       #e7505b;
  --hint:        #4d63f6;
  --good:        #1f9f68;
  --shadow:      0 10px 28px rgba(45,62,128,.14), 0 2px 4px rgba(31,42,84,.07);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: #ffffff;
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}
input {
  font: inherit;
  color: inherit;
}

/* ---------- App shell ---------- */
.app {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  height: 100dvh;
  width: 100vw;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

/* ---------- Top bar ---------- */
.topbar {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  align-items: center;
  padding: 12px 18px 8px;
  gap: 8px;
  background: rgba(255,255,255,.96);
  border-bottom: 1px solid var(--line);
}
.icon-btn {
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--ink);
  background: #eef2ff;
  transition: background var(--t-fast);
}
.icon-btn:hover { background: var(--bg-soft); }
.icon-btn:active { background: var(--line); }

.level-title {
  text-align: center;
  user-select: none;
}
#level-label {
  font-weight: 800;
  font-size: 16px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: #6670ad;
}
.tier {
  display: inline-block;
  margin-top: 2px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg-soft);
  color: var(--ink-soft);
  border: 1px solid var(--line);
}
.tier.easy      { color: #2a8a4f; }
.tier.medium    { color: #3a6fd6; }
.tier.hard      { color: #b8761f; }
.tier.veryhard  { color: #b83a3a; }
.tier.nightmare { color: #7b3aa6; }
.tier.daily     { color: var(--ink); background: var(--ink); color: var(--bg); border-color: var(--ink); }

.hearts {
  display: inline-flex;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 999px;
  background: transparent;
  border: 0;
  min-width: 92px;
  justify-content: center;
}
.heart {
  width: 18px;
  height: 18px;
  display: inline-block;
  color: var(--heart);
  transition: transform var(--t-fast), opacity var(--t-fast);
}
.heart.lost { color: var(--line-strong); opacity: .55; }
.heart.shake { animation: heartShake 360ms ease both; }
@keyframes heartShake {
  0%   { transform: translateX(0) rotate(0); }
  20%  { transform: translateX(-3px) rotate(-8deg); }
  40%  { transform: translateX(3px) rotate(8deg); }
  60%  { transform: translateX(-2px) rotate(-5deg); }
  80%  { transform: translateX(2px) rotate(5deg); }
  100% { transform: translateX(0) rotate(0); }
}

/* ---------- Progress bar ---------- */
.progress {
  height: 2px;
  background: #edf1ff;
  margin: 0;
  border-radius: 0;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width var(--t-med) ease;
}

/* ---------- Board ---------- */
.board-wrapper {
  position: relative;
  overflow: hidden;
  touch-action: none;
  background:
    radial-gradient(circle at 10% 16%, rgba(77,99,246,.04), transparent 24%),
    radial-gradient(circle at 90% 88%, rgba(77,99,246,.035), transparent 26%),
    #ffffff;
}
#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: pointer;
}
#game-canvas.panning { cursor: grabbing; }

.overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.toast {
  pointer-events: none;
  background: var(--ink);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow);
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  opacity: 0;
  transition: opacity var(--t-med), transform var(--t-med);
  max-width: 80%;
  text-align: center;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.hidden { display: none; }

.level-complete {
  pointer-events: auto;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px 32px;
  text-align: center;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  animation: pop var(--t-slow) cubic-bezier(.2,.9,.3,1.2);
}
.level-complete.hidden { display: none; }
.lc-check { color: var(--good); }
.lc-title { font-size: 22px; font-weight: 600; }
.lc-sub   { color: var(--ink-soft); font-size: 14px; }
.lc-next  { margin-top: 12px; min-width: 140px; }

@keyframes pop {
  0%   { transform: scale(.6); opacity: 0; }
  60%  { transform: scale(1.04); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* ---------- Action bar ---------- */
.actions {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 8px 14px 14px;
  border-top: 1px solid var(--line);
  background: rgba(255,255,255,.96);
}
.action {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 6px;
  border-radius: 12px;
  color: var(--ink-soft);
  transition: background var(--t-fast), color var(--t-fast), transform var(--t-fast);
}
.action span {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .02em;
}
.action:hover  { color: var(--ink); background: var(--bg-soft); }
.action:active { transform: scale(.96); }
.action.action-hint {
  color: #ffffff;
  background: var(--hint);
  box-shadow: 0 8px 20px rgba(77,99,246,.24);
}
.action.action-hint:hover { color: #ffffff; background: #4155df; }
.action[disabled] { opacity: .35; cursor: not-allowed; }

/* ---------- Drawer ---------- */
.drawer {
  position: fixed;
  inset: 0;
  z-index: 30;
  pointer-events: none;
  visibility: hidden;
}
.drawer.open { pointer-events: auto; visibility: visible; }

.drawer-scrim {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.35);
  opacity: 0;
  transition: opacity var(--t-med);
}
.drawer.open .drawer-scrim { opacity: 1; }

.drawer-panel {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(360px, 86vw);
  background: var(--bg);
  border-right: 1px solid var(--line);
  padding: 24px 22px;
  overflow-y: auto;
  transform: translateX(-100%);
  transition: transform var(--t-med) cubic-bezier(.2,.8,.3,1);
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.drawer.open .drawer-panel { transform: translateX(0); }

.drawer-close {
  position: absolute;
  top: 12px;
  right: 12px;
  font-size: 24px;
  line-height: 1;
}
#drawer-title { margin: 12px 0 0; font-size: 28px; letter-spacing: -.01em; }
.drawer-sub  { margin: -4px 0 0; color: var(--ink-soft); font-size: 13px; letter-spacing: .04em; }

.drawer-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 4px;
}
.drawer-stats > div {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 8px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.drawer-stats strong { font-size: 18px; font-weight: 600; }
.drawer-stats span   { font-size: 11px; color: var(--ink-faint); text-transform: uppercase; letter-spacing: .08em; }

.drawer-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.drawer-btn {
  text-align: left;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  color: var(--ink);
  font-weight: 500;
  transition: background var(--t-fast), border-color var(--t-fast);
}
.drawer-btn:hover { background: var(--line); }

.drawer-section h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--ink-faint);
  margin: 8px 0 8px;
}
.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 6px;
  font-size: 14px;
  cursor: pointer;
}
.toggle input { accent-color: var(--ink); width: 18px; height: 18px; }

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  visibility: hidden;
  pointer-events: none;
}
.modal.open { visibility: visible; pointer-events: auto; }

.modal-scrim {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.45);
  opacity: 0;
  transition: opacity var(--t-med);
}
.modal.open .modal-scrim { opacity: 1; }

.modal-content {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, calc(-50% + 12px));
  width: min(420px, 92vw);
  max-height: 88dvh;
  overflow-y: auto;
  background: var(--bg);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  padding: 22px 22px 18px;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity var(--t-med), transform var(--t-med) cubic-bezier(.2,.8,.3,1);
}
.modal.open .modal-content {
  transform: translate(-50%, -50%);
  opacity: 1;
}
.modal-wide { width: min(680px, 96vw); }
.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 22px;
  line-height: 1;
}
.modal h2 { margin: 4px 0 14px; font-size: 22px; font-weight: 600; }
.modal-body { color: var(--ink-soft); line-height: 1.55; font-size: 15px; }
.modal-body ul { padding-left: 20px; margin: 10px 0; }
.modal-body li { margin: 4px 0; }
.note { font-size: 13px; color: var(--ink-faint); }
.heart-inline { color: var(--heart); font-weight: 700; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 18px;
  gap: 8px;
}

.btn-primary {
  background: var(--ink);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 10px;
  font-weight: 600;
  transition: filter var(--t-fast), transform var(--t-fast);
}
.btn-primary:hover  { filter: brightness(1.1); }
.btn-primary:active { transform: scale(.97); }

.btn-secondary {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 8px 14px;
  border-radius: 10px;
  font-weight: 500;
  transition: background var(--t-fast);
}
.btn-secondary:hover { background: var(--line); }

/* ---------- Levels modal ---------- */
.levels-controls {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.levels-controls input {
  flex: 1;
  min-width: 0;
  padding: 8px 12px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.difficulty-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 14px;
  overflow-x: auto;
}
.tab {
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-soft);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tab:hover  { color: var(--ink); }
.tab.active { color: var(--ink); border-bottom-color: var(--ink); }

.levels-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(58px, 1fr));
  gap: 6px;
  max-height: 50dvh;
  overflow-y: auto;
  padding: 4px;
}
.lvl-cell {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--t-fast), color var(--t-fast), transform var(--t-fast);
}
.lvl-cell:hover { background: var(--line); color: var(--ink); }
.lvl-cell.solved {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
}
.lvl-cell.current {
  outline: 2px solid var(--hint);
  outline-offset: 2px;
}
.lvl-cell.solved::after {
  content: "";
  position: absolute;
  top: 4px;
  right: 4px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--good);
}

.levels-pager {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 12px;
  font-size: 13px;
  color: var(--ink-soft);
}

/* ---------- Achievements ---------- */
.ach-counter {
  font-size: 13px;
  color: var(--ink-faint);
  font-weight: 500;
}
.achievements-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
  max-height: 60dvh;
  overflow-y: auto;
  padding: 2px;
}
.ach {
  display: grid;
  grid-template-columns: 36px 1fr;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.ach.locked   { opacity: .5; }
.ach.unlocked { border-color: var(--good); }
.ach-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  background: var(--bg);
  border: 1px solid var(--line);
}
.ach.unlocked .ach-icon { background: var(--good); color: white; border-color: var(--good); }
.ach-title { font-weight: 600; font-size: 14px; }
.ach-desc  { font-size: 12px; color: var(--ink-faint); margin-top: 2px; }

/* ---------- Misc ---------- */
.hidden { display: none !important; }

@media (max-width: 380px) {
  .actions { padding: 6px 8px 10px; }
  .action span { font-size: 10px; }
  #level-label { font-size: 15px; }
}

@media (prefers-reduced-motion: reduce) {
  .level-complete { animation: none; }
  .heart.shake { animation: none; }
  .drawer-panel, .modal-content, .drawer-scrim, .modal-scrim, .toast,
  .icon-btn, .action, .drawer-btn, .lvl-cell {
    transition: none !important;
  }
}
