:root {
  --bg-a: #ffe9dc;
  --bg-b: #f6c9c0;
  --ink: #5a3a36;
  --muted: #9a706a;
  --card: rgba(255, 255, 255, 0.82);
  --accent: #8f7bff;
  --accent-soft: #e5deff;
  --good: #63d39b;
  --shadow: 0 8px 24px rgba(120, 60, 50, 0.18);
  --radius: 18px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(circle at 50% 40%, var(--bg-a), var(--bg-b));
  color: var(--ink);
  font-family: 'Jua', -apple-system, 'Apple SD Gothic Neo', sans-serif;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#app { position: fixed; inset: 0; }
#app canvas { display: block; touch-action: none; cursor: crosshair; }

.panel {
  position: fixed;
  top: 16px;
  left: 16px;
  width: min(300px, calc(100vw - 32px));
  padding: 14px 16px;
  background: var(--card);
  backdrop-filter: blur(8px);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.panel h1 { margin: 0 0 10px; font-size: 22px; font-weight: 400; }
.meter { height: 14px; border-radius: 999px; background: var(--accent-soft); overflow: hidden; }
.meter-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, #9ee6ff, var(--accent), #ff9ec4);
  transition: width 0.3s ease;
}
.stats { display: flex; justify-content: space-between; margin-top: 8px; font-size: 15px; color: var(--muted); }
.stats b { color: var(--ink); font-weight: 400; }

.hint {
  position: fixed;
  left: 16px;
  bottom: 92px;
  margin: 0;
  padding: 10px 14px;
  border-radius: 14px;
  background: var(--card);
  box-shadow: var(--shadow);
  font-size: 14px;
  line-height: 1.6;
  color: var(--muted);
  transition: opacity 0.8s 4s;
}
.hint b { color: var(--ink); font-weight: 400; }
.hint.faded { opacity: 0; pointer-events: none; }

.toolbar {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  padding: 8px;
  background: var(--card);
  border-radius: 999px;
  box-shadow: var(--shadow);
  max-width: calc(100vw - 32px);
}
.toolbar button, .done-card button {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 0;
  border-radius: 999px;
  padding: 10px 16px;
  background: white;
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  cursor: pointer;
  box-shadow: 0 2px 0 rgba(120, 60, 50, 0.12);
  transition: transform 0.1s, background 0.2s;
  white-space: nowrap;
}
.toolbar button:hover { transform: translateY(-2px); }
.toolbar button:active { transform: translateY(1px); }
.toolbar button.on { background: var(--accent); color: white; }
.toolbar button.icon { padding: 10px 14px; }

@media (max-width: 640px) {
  .toolbar .label { display: none; }
  .toolbar button { font-size: 20px; padding: 10px 14px; }
  .hint { display: none; }
}

.toast {
  position: fixed;
  top: 18px;
  left: 50%;
  transform: translate(-50%, -24px);
  opacity: 0;
  padding: 10px 20px;
  border-radius: 999px;
  background: var(--card);
  box-shadow: var(--shadow);
  font-size: 18px;
  transition: transform 0.35s cubic-bezier(0.3, 1.4, 0.6, 1), opacity 0.25s;
  pointer-events: none;
  max-width: calc(100vw - 32px);
  text-align: center;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }
@media (max-width: 640px) { .toast { top: 130px; } }

.done {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.5s;
}
.done.show { opacity: 1; }
.done.show .done-card { pointer-events: auto; transform: scale(1); }
.done-card {
  padding: 24px 32px;
  border-radius: 24px;
  background: var(--card);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
  text-align: center;
  transform: scale(0.8);
  transition: transform 0.5s cubic-bezier(0.3, 1.6, 0.6, 1);
  max-width: calc(100vw - 32px);
}
.done-card h2 { font-weight: 400; margin: 8px 0; }
.done-time { color: var(--muted); margin: 0 0 16px; }
.done-card button { margin: 0 auto; background: var(--accent); color: white; }

.loading, .error {
  position: fixed;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  background: radial-gradient(circle at 50% 40%, var(--bg-a), var(--bg-b));
  font-size: 20px;
  transition: opacity 0.6s;
}
.loading.hidden { opacity: 0; pointer-events: none; }
.loading-bot { font-size: 56px; animation: wobble 1s ease-in-out infinite alternate; }
@keyframes wobble { from { transform: rotate(-10deg); } to { transform: rotate(10deg); } }
.error { display: none; padding: 24px; color: #b03a3a; }
.error.show { display: grid; }
