:root {
  --bg: #faf8ef;
  --board: #bbada0;
  --cell: #eee4da;
  --ink: #776e65;
  --ink-strong: #4a443f;
  --accent: #edc22e;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink-strong);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

.wrap {
  max-width: 500px;
  margin: 0 auto;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
}

/* ---------- header ---------- */
.top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.top h1 {
  margin: 0;
  font-size: 40px;
  line-height: 1;
  letter-spacing: -1px;
  color: var(--ink-strong);
}

.tagline {
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--ink);
}

.scores {
  display: flex;
  align-items: center;
  gap: 8px;
}

.score-box {
  background: var(--cell);
  border-radius: var(--radius);
  padding: 8px 14px;
  text-align: center;
  min-width: 68px;
}

.score-box .label {
  display: block;
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--ink);
}

.score-box .value {
  display: block;
  font-size: 20px;
  font-weight: 700;
  color: var(--ink-strong);
}

/* ---------- buttons ---------- */
button {
  font: inherit;
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
}

.icon-btn {
  width: 42px;
  height: 42px;
  background: var(--cell);
  color: var(--ink-strong);
  font-size: 17px;
  display: grid;
  place-items: center;
  transition: background 0.15s ease;
}

.icon-btn:hover { background: #e2d7cb; }
.icon-btn:active { transform: scale(0.94); }

.primary {
  background: var(--accent);
  color: #6b5410;
  font-weight: 700;
  padding: 11px 18px;
  transition: filter 0.15s ease;
}

.primary:hover { filter: brightness(1.06); }
.primary:active { transform: scale(0.97); }
.primary:disabled { opacity: 0.55; cursor: progress; }

.ghost {
  background: transparent;
  color: var(--ink);
  text-decoration: underline;
  padding: 8px 4px;
  font-size: 13px;
}

.ghost:hover { color: var(--ink-strong); }

/* ---------- board ---------- */
.board-wrap { position: relative; }

.board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 10px;
  background: var(--board);
  border-radius: var(--radius);
  padding: 10px;
  aspect-ratio: 1 / 1;
  touch-action: none;
}

.cell {
  display: grid;
  place-items: center;
  background: var(--cell);
  border-radius: var(--radius);
  font-size: clamp(22px, 7vw, 40px);
  font-weight: 800;
  color: #f9f6f2;
  line-height: 1;
  user-select: none;
}

.cell[data-v="2"]     { background: #eee4da; color: var(--ink); }
.cell[data-v="4"]     { background: #ede0c8; color: var(--ink); }
.cell[data-v="8"]     { background: #f2b179; }
.cell[data-v="16"]    { background: #f59563; }
.cell[data-v="32"]    { background: #f67c5f; }
.cell[data-v="64"]    { background: #f65e3b; }
.cell[data-v="128"]   { background: #edcf72; font-size: clamp(20px, 6.2vw, 36px); }
.cell[data-v="256"]   { background: #edcc61; font-size: clamp(20px, 6.2vw, 36px); }
.cell[data-v="512"]   { background: #edc850; font-size: clamp(20px, 6.2vw, 36px); }
.cell[data-v="1024"]  { background: #edc53f; font-size: clamp(17px, 5.2vw, 30px); }
.cell[data-v="2048"]  { background: #edc22e; font-size: clamp(17px, 5.2vw, 30px); }
.cell[data-v="big"]   { background: #3c3a32; font-size: clamp(13px, 3.6vw, 22px); }

.cell.pop { animation: pop 0.16s ease; }

@keyframes pop {
  from { transform: scale(0.86); }
  to   { transform: scale(1); }
}

/* ---------- overlay ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(238, 228, 218, 0.78);
  border-radius: var(--radius);
  backdrop-filter: blur(2px);
}

.overlay-card { text-align: center; padding: 20px; }
.overlay-card h2 { margin: 0 0 6px; font-size: 30px; }
.overlay-card p { margin: 0 0 18px; color: var(--ink); }

/* ---------- foot ---------- */
.foot {
  margin-top: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.keys {
  margin: 0;
  font-size: 12px;
  color: var(--ink);
}

kbd {
  display: inline-block;
  min-width: 18px;
  padding: 1px 4px;
  margin: 0 1px;
  font: inherit;
  font-size: 11px;
  text-align: center;
  background: var(--cell);
  border-radius: 4px;
  border-bottom: 2px solid #d3c7b8;
}

/* ---------- side panel ---------- */
.panel {
  position: fixed;
  top: 0;
  right: 0;
  width: min(380px, 100%);
  height: 100%;
  background: var(--bg);
  border-left: 1px solid #e4dcd1;
  box-shadow: -8px 0 28px rgba(0, 0, 0, 0.12);
  z-index: 10;
  display: flex;
  flex-direction: column;
  animation: slide-in 0.2s ease;
}

@keyframes slide-in {
  from { transform: translateX(24px); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 18px 12px;
  border-bottom: 1px solid #e4dcd1;
}

.panel-head h2 { margin: 0; font-size: 18px; }

.panel-body {
  padding: 18px;
  overflow-y: auto;
  flex: 1;
}

.hint {
  margin: 0 0 14px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--ink);
}

#q-name,
#q-type {
  font: inherit;
  width: 100%;
  padding: 11px 12px;
  border: 1px solid #ded4c7;
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink-strong);
}

#q-name:focus,
#q-type:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.row {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.row #q-type { flex: 0 0 104px; width: auto; }
.row .primary { flex: 1; }

.dns-out {
  margin: 14px 0 0;
  padding: 12px;
  min-height: 84px;
  max-height: 300px;
  overflow: auto;
  background: var(--cell);
  border-radius: var(--radius);
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--ink-strong);
}

.dns-out .ttl { color: var(--ink); }
.dns-out .err { color: #b3401f; }

.cfg {
  margin-top: 18px;
  font-size: 13px;
  color: var(--ink);
}

.cfg summary { cursor: pointer; font-weight: 600; color: var(--ink-strong); }
.cfg p { line-height: 1.6; }

.cfg code {
  display: block;
  margin: 8px 0;
  padding: 10px 12px;
  background: var(--cell);
  border-radius: var(--radius);
  font-size: 12px;
  word-break: break-all;
  color: var(--ink-strong);
}

.tiny { font-size: 11.5px; color: var(--ink); }

@media (max-width: 420px) {
  .top h1 { font-size: 32px; }
  .board { gap: 8px; padding: 8px; }
}