:root {
  --bg-1: #050810;
  --bg-2: #0b1226;
  --panel: rgba(255, 255, 255, 0.08);
  --panel-strong: rgba(255, 255, 255, 0.11);
  --border: rgba(255, 255, 255, 0.09);
  --text: #f6f8ff;
  --muted: rgba(246, 248, 255, 0.68);
  --gold: #fbbf24;
  --danger: #fb7185;
  --green: #4ade80;
  --radius-xl: 30px;
  --radius-lg: 22px;
  --radius-md: 18px;
  --shadow-lg: 0 24px 70px rgba(0, 0, 0, 0.42);
  --shadow-md: 0 14px 34px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 18px 18px 32px;
  overflow-x: hidden;
  color: var(--text);
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  background:
    radial-gradient(1200px 800px at 15% 10%, rgba(124, 58, 237, 0.22), transparent 55%),
    radial-gradient(1000px 700px at 85% 85%, rgba(37, 99, 235, 0.22), transparent 55%),
    linear-gradient(160deg, var(--bg-1), var(--bg-2));
}

/* ---- Animated background ---- */
.bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}

.blob {
  position: absolute;
  width: 38vmax;
  height: 38vmax;
  border-radius: 50%;
  filter: blur(72px);
  opacity: 0.42;
  animation: drift 16s ease-in-out infinite alternate;
}

.blob-1 {
  top: -12vmax;
  left: -9vmax;
  background: radial-gradient(circle at 30% 30%, #7c3aed, transparent 68%);
}

.blob-2 {
  right: -10vmax;
  bottom: -14vmax;
  background: radial-gradient(circle at 30% 30%, #2563eb, transparent 68%);
  animation-delay: -4s;
}

.blob-3 {
  left: 32%;
  bottom: -18vmax;
  width: 26vmax;
  height: 26vmax;
  opacity: 0.2;
  background: radial-gradient(circle at 30% 30%, #f59e0b, transparent 68%);
  animation-delay: -8s;
}

@keyframes drift {
  to {
    transform: translate3d(4vmax, -3vmax, 0) scale(1.08);
  }
}

/* ---- App shell ---- */
.app {
  width: min(100%, 580px);
  display: grid;
  gap: 14px;
}

/* ---- Brand ---- */
.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.logo {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  font-size: 24px;
  border-radius: 16px;
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0.04));
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
}

h1 {
  margin: 0;
  font-size: clamp(22px, 4vw, 32px);
  letter-spacing: 0.045em;
  background: linear-gradient(90deg, #ffffff, #fbbf24, #fde68a);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* ---- HUD row ---- */
.hud-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.hud-cell {
  flex: 1;
  padding: 10px 12px;
  text-align: center;
  border-radius: var(--radius-md);
  background: var(--panel);
  border: 1px solid var(--border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: var(--shadow-md);
}

.hud-label {
  display: block;
  margin-bottom: 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.hud-value {
  display: block;
  font-size: 22px;
  font-weight: 900;
  line-height: 1.1;
}

/* ---- SVG Timer ring ---- */
.timer-wrap {
  position: relative;
  width: 64px;
  height: 64px;
  flex-shrink: 0;
}

.timer-ring {
  width: 64px;
  height: 64px;
  transform: rotate(-90deg);
}

.timer-track {
  fill: none;
  stroke: var(--border);
  stroke-width: 5;
}

.timer-arc {
  fill: none;
  stroke: var(--green);
  stroke-width: 5;
  stroke-linecap: round;
  /* circumference = 2 * PI * 24 ≈ 150.796 */
  stroke-dasharray: 150.796;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 0.9s linear, stroke 0.4s ease;
}

.timer-text {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 17px;
  font-weight: 900;
  color: var(--text);
}

/* ---- Board wrap ---- */
.board-wrap {
  position: relative;
  padding: 16px;
  display: grid;
  gap: 12px;
  border-radius: var(--radius-xl);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.11), rgba(255, 255, 255, 0.05));
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

/* ---- Task row ---- */
.task-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background: var(--panel);
  border: 1px solid var(--border);
}

.task-word-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.task-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.task-word {
  font-size: clamp(20px, 4vw, 28px);
  font-weight: 900;
  color: var(--gold);
  letter-spacing: 0.01em;
}

.etalon-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.etalon-canvas {
  width: 128px;
  height: 128px;
  background: #fff;
  border-radius: 12px;
  border: 2px solid rgba(255, 255, 255, 0.18);
  box-shadow: var(--shadow-md);
  display: block;
}

/* ---- Drawing canvas ---- */
#pad {
  width: 100%;
  aspect-ratio: 1 / 1;
  touch-action: none;
  background: #fff;
  border-radius: var(--radius-md);
  border: 2px solid rgba(255, 255, 255, 0.18);
  cursor: crosshair;
  box-shadow: var(--shadow-md);
  display: block;
}

/* ---- Similarity bar ---- */
.sim-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sim-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}

.sim-bar-wrap {
  flex: 1;
  height: 6px;
  border-radius: 99px;
  background: var(--panel);
  overflow: hidden;
}

.sim-bar-fill {
  height: 100%;
  width: 0%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--green), #86efac);
  transition: width 0.4s ease, background 0.4s ease;
}

.sim-pct {
  font-size: 12px;
  font-weight: 800;
  color: var(--text);
  min-width: 32px;
  text-align: right;
}

/* ---- Toolbar ---- */
.toolbar {
  display: grid;
  gap: 8px;
}

.tool-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tool-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--panel);
  border: 1.5px solid var(--border);
  color: var(--text);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 18px;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.08s ease;
  flex-shrink: 0;
}

.tool-btn:hover {
  background: var(--panel-strong);
  filter: brightness(1.15);
}

.tool-btn:active {
  transform: scale(0.93);
}

.tool-btn.active {
  border-color: var(--gold);
  box-shadow: 0 0 0 1px var(--gold), 0 0 12px rgba(251, 191, 36, 0.25);
}

.brush-dot {
  border-radius: 50%;
  background: var(--text);
  display: block;
}

.tool-sep {
  width: 1px;
  height: 28px;
  background: var(--border);
  flex-shrink: 0;
  margin: 0 2px;
}

.tool-done {
  flex: 1;
  height: 44px;
  padding: 0 16px;
  font-size: 15px;
  font-weight: 800;
  white-space: nowrap;
}

/* ---- Buttons ---- */
.btn {
  padding: 12px 18px;
  border-radius: 16px;
  font-weight: 800;
  font: inherit;
  cursor: pointer;
  color: var(--text);
  background: var(--panel-strong);
  border: 1px solid var(--border);
  transition: transform 0.08s ease, filter 0.15s ease;
}

.btn:hover {
  filter: brightness(1.15);
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.btn-primary {
  color: #0b1226;
  background: linear-gradient(135deg, var(--gold), #f59e0b);
  border: none;
  box-shadow: 0 10px 26px rgba(245, 158, 11, 0.35);
}

/* ---- Overlay ---- */
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: var(--radius-xl);
  background: rgba(5, 8, 16, 0.82);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 10;
  padding: 16px;
}

.overlay.hidden {
  display: none;
}

.panel-box {
  width: min(100%, 340px);
  padding: 22px 20px;
  text-align: center;
  border-radius: var(--radius-lg);
  background: var(--panel-strong);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  display: grid;
  gap: 14px;
}

.panel-box h2 {
  margin: 0;
  font-size: clamp(20px, 4vw, 26px);
}

.ov-emoji {
  font-size: 40px;
  line-height: 1;
}

.ov-text {
  margin: 0;
  font-size: 14px;
  color: var(--muted);
  line-height: 1.5;
}

/* Result overlay canvas */
.res-canvas {
  width: 160px;
  height: 160px;
  margin: 0 auto;
  background: #fff;
  border-radius: 14px;
  border: 2px solid rgba(255, 255, 255, 0.18);
  box-shadow: var(--shadow-md);
  display: block;
}

/* ---- Mobile ---- */
@media (max-width: 480px) {
  body {
    padding: 10px 10px 24px;
  }

  .task-row {
    flex-direction: row;
    align-items: center;
  }

  .etalon-canvas {
    width: 96px;
    height: 96px;
  }

  .tool-btn {
    width: 40px;
    height: 40px;
  }

  .hud-value {
    font-size: 18px;
  }
}

@media (max-width: 360px) {
  .etalon-canvas {
    width: 80px;
    height: 80px;
  }
}
