:root {
  --bg: #F6F1E7;
  --ink: #2A241C;
  --ink-60: #7A7060;
  --line: #E4DACA;
  --card: #FFFFFF;
  --accent: #E2703A;
}

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: Pretendard, -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  overscroll-behavior: none;
  touch-action: manipulation;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: max(10px, env(safe-area-inset-top)) 14px calc(10px + env(safe-area-inset-bottom));
}

.bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 2px 12px;
}
.icon {
  width: 40px; height: 40px;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 12px;
  font-size: 17px;
  cursor: pointer;
}
.lv { flex: 1; line-height: 1.15; }
.lvNum { font-size: 20px; font-weight: 800; letter-spacing: -0.02em; }
.lvNum::before { content: 'LEVEL '; font-size: 11px; font-weight: 700; color: var(--ink-60); letter-spacing: 0.08em; }
.lvSub { display: block; font-size: 11px; color: var(--ink-60); margin-top: 2px; }
.moves { font-size: 22px; font-weight: 800; }
.moves small { font-size: 11px; font-weight: 600; color: var(--ink-60); margin-left: 2px; }

.stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}
/* 캔버스가 무대를 꽉 채워야 layout()이 제 크기로 계산한다 */
#board { display: block; width: 100%; height: 100%; touch-action: none; }

.tools {
  display: flex;
  gap: 8px;
  padding-top: 12px;
}
.tool {
  flex: 1;
  padding: 11px 0 9px;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 14px;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-60);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.tool span { font-size: 17px; }
.tool:active { background: #FBF4EA; border-color: var(--accent); }
.tool:disabled { opacity: .4; }

.sheet {
  position: fixed;
  inset: 0;
  background: rgba(30, 24, 16, .42);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 10;
}
.sheet.hidden { display: none; }
.sheetCard {
  width: 100%;
  max-width: 480px;
  background: var(--card);
  border-radius: 20px 20px 0 0;
  padding: 22px 18px calc(22px + env(safe-area-inset-bottom));
}
.sheetCard.tall { max-height: 76vh; overflow: auto; }
.sheetCard h2 { margin: 0 0 6px; font-size: 20px; font-weight: 800; }
.sheetCard p { margin: 0 0 16px; font-size: 14px; color: var(--ink-60); }
.sheetRow { display: flex; gap: 8px; }

.primary, .ghost {
  flex: 1;
  padding: 14px;
  border-radius: 13px;
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  border: 1px solid transparent;
}
.primary { background: var(--ink); color: #fff; }
.ghost { background: #fff; border-color: var(--line); color: var(--ink); }
.wide { width: 100%; margin-top: 12px; }

.grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}
.grid button {
  aspect-ratio: 1;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  font: inherit;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
}
.grid button.done { background: #F2EADC; color: var(--ink-60); }
.grid button.now { border-color: var(--accent); color: var(--accent); }
