:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #111827);
  --hint: var(--tg-theme-hint-color, #6b7280);
  --accent: var(--tg-theme-button-color, #2481cc);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --surface: var(--tg-theme-secondary-bg-color, #f1f3f6);
  --danger: #e5484d;
  --success: #30a46c;
}

@media (prefers-color-scheme: dark) {
  :root:not(.tg) {
    --bg: #17212b;
    --text: #f5f5f5;
    --hint: #8b9aa7;
    --surface: #232e3c;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.app {
  max-width: 420px;
  margin: 0 auto;
  padding: 16px 16px 24px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.head { text-align: center; }
.shield { font-size: 32px; }
h1 { font-size: 20px; margin: 4px 0 2px; }
.muted { color: var(--hint); margin: 0; font-size: 14px; }
.hint { text-align: center; min-height: 20px; }

.instruction { margin: 0; text-align: center; font-size: 17px; }
.notice {
  margin: 0;
  padding: 8px 12px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--danger) 14%, transparent);
  text-align: center;
  font-size: 14px;
}
.notice.ok { background: color-mix(in srgb, var(--success) 16%, transparent); }

.stage {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 20px;
  background: var(--surface);
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.stage.locked { pointer-events: none; opacity: .6; }

.el {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

/* slider */
.lane { border-radius: 16px; background: color-mix(in srgb, var(--text) 7%, transparent); }
.notch { border: 3px dashed color-mix(in srgb, var(--text) 45%, transparent); border-radius: 14px; }
.piece {
  border-radius: 14px;
  background: var(--accent);
  box-shadow: 0 4px 14px rgba(0, 0, 0, .25);
  font-size: 30px;
}

/* drag */
.target { border: 3px dashed var(--accent); border-radius: 50%; background: color-mix(in srgb, var(--accent) 10%, transparent); }
.item { font-size: 40px; filter: drop-shadow(0 4px 8px rgba(0, 0, 0, .25)); }

/* rotate */
.dial { border-radius: 50%; border: 2px solid color-mix(in srgb, var(--text) 18%, transparent); }
.mark { width: 22px; height: 22px; border-radius: 50%; background: var(--danger); box-shadow: 0 0 0 5px color-mix(in srgb, var(--danger) 25%, transparent); }
.arrow svg { width: 100%; height: 100%; overflow: visible; }

/* hold */
.shape svg { width: 100%; height: 100%; }
.ring { width: 96px; height: 96px; }
.ring circle { fill: none; stroke: var(--accent); stroke-width: 8; stroke-linecap: round; }

.result { text-align: center; display: flex; flex-direction: column; gap: 12px; align-items: stretch; margin-top: 12px; }
.result-icon { font-size: 56px; }
.result-text { margin: 0; font-size: 17px; white-space: pre-line; }
.channels { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.channels a, .channels span {
  display: block;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
}
.channels a { color: var(--accent); }

.btn {
  border: 0;
  border-radius: 12px;
  padding: 13px 16px;
  font: inherit;
  font-weight: 600;
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
}
.btn-secondary { background: var(--surface); color: var(--text); }

.loader { display: flex; justify-content: center; padding: 32px 0; }
.spinner {
  width: 32px; height: 32px;
  border: 3px solid color-mix(in srgb, var(--accent) 25%, transparent);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.preview-bar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 13px; color: var(--hint); }
.preview-bar button { font: inherit; border: 0; border-radius: 8px; padding: 6px 10px; background: var(--surface); color: var(--text); cursor: pointer; }

[hidden] { display: none !important; }
