:root {
  --bg: #faf7f2;
  --ink: #1c1a17;
  --muted: #8a8378;
  --card: #ffffff;
  --accent: #c0392b;
  --accent-dark: #96281b;
  --gold: #c9a227;
  --line: #e6e0d6;
  --hit: #2e9e5b;
  --miss: #d64545;
  --edge: #b9b2a6;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: ui-rounded, "SF Pro Rounded", -apple-system, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

header { text-align: center; padding: 20px 16px 8px; }
h1 { font-size: 1.9rem; letter-spacing: -0.02em; }
h1 .tld { color: var(--accent); }
.tagline { color: var(--muted); font-size: 0.9rem; margin-top: 2px; }

main {
  width: 100%;
  max-width: 440px;
  padding: 8px 16px 24px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.screen { display: flex; flex-direction: column; gap: 14px; align-items: center; }
.hidden, [hidden] { display: none !important; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px;
  width: 100%;
  box-shadow: 0 2px 10px rgba(60, 50, 30, 0.05);
}

/* ---- intro ---- */
.intro-card { text-align: center; }
.intro-art { font-size: 3rem; margin-bottom: 6px; }
.intro-card h2 { margin-bottom: 12px; }
.rules { text-align: left; padding-left: 22px; display: grid; gap: 8px; margin-bottom: 12px; }
.rules-hint { color: var(--muted); font-size: 0.85rem; margin-bottom: 16px; }

/* ---- buttons ---- */
.btn {
  font: inherit;
  font-weight: 700;
  border: none;
  border-radius: 12px;
  padding: 13px 22px;
  cursor: pointer;
  transition: transform 0.06s ease, background 0.15s ease;
  touch-action: manipulation;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-primary { background: var(--accent); color: #fff; width: 100%; max-width: 320px; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-ghost { background: transparent; color: var(--ink); border: 1.5px solid var(--line); }

/* ---- study ---- */
.study-timer {
  width: 52px; height: 52px;
  border-radius: 50%;
  background: var(--ink); color: #fff;
  display: grid; place-items: center;
  font-size: 1.4rem; font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.art-frame {
  width: 100%;
  border: 10px solid #3c2f1e;
  border-radius: 4px;
  outline: 1px solid var(--gold);
  outline-offset: -7px;
  background: #000;
  box-shadow: 0 8px 24px rgba(60, 40, 10, 0.25);
}
.art-frame img { width: 100%; display: block; user-select: none; -webkit-user-select: none; }
.study-hint { color: var(--muted); font-size: 0.9rem; }

/* ---- draw ---- */
.draw-header { width: 100%; display: flex; align-items: center; gap: 10px; }
.timebar { flex: 1; height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.timebar-fill { height: 100%; width: 100%; background: var(--accent); border-radius: 99px; transition: width 0.3s linear; }
.time-left { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 0.95rem; min-width: 44px; text-align: right; }

.canvas-wrap {
  position: relative;
  width: 100%;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 2px 10px rgba(60, 50, 30, 0.06);
}
#sketch-canvas { width: 100%; display: block; touch-action: none; cursor: crosshair; }

.peek-overlay {
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: grid; place-items: center;
  animation: fadein 0.15s ease;
}
.peek-overlay img { max-width: 100%; max-height: 100%; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

.toolbar {
  display: flex; gap: 6px; align-items: center; justify-content: center;
  width: 100%; flex-wrap: wrap;
}
.tool {
  font: inherit; font-size: 1.05rem;
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: 10px;
  width: 46px; height: 42px;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 3px;
  position: relative;
  touch-action: manipulation;
}
.tool.active { border-color: var(--ink); background: #f1ede5; }
.tool.peek { width: auto; padding: 0 12px; font-weight: 700; }
.tool:disabled { opacity: 0.35; cursor: default; }
.tool-sep { width: 1px; height: 24px; background: var(--line); margin: 0 4px; }
.dot { border-radius: 50%; background: var(--ink); position: absolute; right: 6px; bottom: 6px; }
.dot-s { width: 4px; height: 4px; }
.dot-l { width: 8px; height: 8px; }

/* ---- result ---- */
.score-block { text-align: center; padding-top: 6px; }
.score-num {
  font-size: 4.2rem; font-weight: 900; line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}
.score-sub { font-weight: 700; margin-top: 2px; }
.score-detail { color: var(--muted); font-size: 0.85rem; margin-top: 4px; }

.compare { display: flex; gap: 12px; width: 100%; }
.compare figure { flex: 1; min-width: 0; }
.compare img, .compare canvas {
  width: 100%; display: block;
  border: 1px solid var(--line); border-radius: 8px;
  background: #fff;
}
.compare figcaption { text-align: center; color: var(--muted); font-size: 0.8rem; margin-top: 5px; }

.overlay-details { width: 100%; }
.overlay-details summary { cursor: pointer; color: var(--muted); font-size: 0.9rem; margin-bottom: 8px; }
#overlay-canvas { width: 100%; display: block; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.overlay-legend { font-size: 0.78rem; color: var(--muted); margin-top: 6px; }
.lg { display: inline-block; width: 10px; height: 10px; border-radius: 2px; vertical-align: middle; }
.lg-hit { background: var(--hit); }
.lg-close { background: #e0a52e; }
.lg-miss { background: var(--miss); }
.lg-edge { background: var(--edge); }

.fact-card h3 { margin-bottom: 6px; font-size: 1rem; }
.fact-card p { font-size: 0.92rem; line-height: 1.5; color: #4a453d; }

.share-row { display: flex; gap: 10px; width: 100%; }
.share-row .btn-primary { flex: 1; }
.share-toast { color: var(--hit); font-weight: 700; font-size: 0.9rem; }

.stats { color: var(--muted); font-size: 0.85rem; }

footer { padding: 16px; color: var(--muted); font-size: 0.78rem; text-align: center; }
