:root {
  color-scheme: light;
  --ink: #172033;
  --glass: rgba(235, 250, 255, 0.82);
  --line: rgba(23, 32, 51, 0.16);
  --green: #14804a;
  --blue: #2563eb;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  font-family: "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 14%, rgba(255, 255, 255, 0.82), transparent 21%),
    linear-gradient(135deg, #cfefff 0%, #edf8ff 45%, #d8f7ed 100%);
}

body {
  min-height: 100dvh;
  overscroll-behavior: none;
}

button,
input,
a {
  font: inherit;
}

.game-shell {
  width: min(100vw, 1180px);
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  padding: 12px;
  position: relative;
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 8px;
  background: #72cae8;
  box-shadow: 0 18px 55px rgba(19, 56, 101, 0.22);
  touch-action: none;
}

.fullscreen-button,
.corner-actions a,
.stats-panel,
.retry-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--glass);
  color: #172033;
  box-shadow: 0 12px 28px rgba(19, 56, 101, 0.16);
  backdrop-filter: blur(8px);
}

.fullscreen-button {
  position: absolute;
  top: 22px;
  right: 22px;
  z-index: 5;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  min-height: 44px;
  padding: 0;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
}

.fullscreen-button:disabled {
  display: none;
}

.stats-panel {
  position: absolute;
  z-index: 7;
  right: 24px;
  top: 78px;
  width: min(340px, calc(100% - 36px));
  max-height: calc(100dvh - 124px);
  overflow: auto;
  padding: 12px;
  transform: none;
}

.stats-panel.drag-ready {
  cursor: grab;
}

.stats-panel.dragging {
  cursor: grabbing;
  user-select: none;
}

.stats-panel.hidden,
.retry-panel.hidden,
.success-mark.hidden {
  display: none;
}

.retry-panel {
  position: absolute;
  z-index: 7;
  left: 50%;
  top: 50%;
  width: min(420px, calc(100% - 36px));
  padding: 22px;
  text-align: center;
  transform: translate(-50%, -50%);
}

.retry-panel h1,
.retry-panel p {
  margin: 0;
}

.retry-panel h1 {
  font-size: 34px;
  line-height: 1.08;
}

.retry-panel p {
  margin-top: 10px;
  color: #405166;
  font-size: 18px;
  font-weight: 800;
  line-height: 1.35;
}

#retryBtn {
  margin-top: 18px;
  background: var(--blue);
}

.stats-panel h1,
.stats-panel h2,
.stats-panel p {
  margin: 0;
}

.stats-panel h1 {
  font-size: 22px;
  line-height: 1.08;
}

#summaryText {
  margin-top: 4px;
  color: #405166;
  font-size: 13px;
  font-weight: 700;
}

.task-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

label {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
  align-items: center;
  color: #172033;
  font-weight: 900;
}

label input {
  grid-column: 1 / -1;
}

input {
  width: 100%;
  min-height: 34px;
  border: 2px solid rgba(23, 32, 51, 0.18);
  border-radius: 8px;
  padding: 0 10px;
  background: white;
  color: #172033;
  font-size: 17px;
  font-weight: 900;
}

.check-slot {
  display: inline-grid;
  place-items: center;
  width: 22px;
  aspect-ratio: 1;
  border-radius: 50%;
  color: #16a34a;
  font-size: 21px;
  font-weight: 900;
}

.mode-section,
.frequency-section {
  margin-top: 10px;
}

.mode-section h2,
.frequency-section h2 {
  font-size: 16px;
}

.mode-section p {
  margin-top: 3px;
  color: #405166;
  font-size: 12px;
  font-weight: 700;
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 6px;
}

.frequency-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 6px;
}

.swatch {
  display: inline-block;
  width: 12px;
  aspect-ratio: 1;
  border-radius: 50%;
}

.color-label {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

#answerMessage {
  min-height: 18px;
  margin-top: 8px;
  color: #9f1239;
  font-size: 13px;
  font-weight: 800;
}

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

button {
  min-height: 38px;
  border: 0;
  border-radius: 8px;
  padding: 0 16px;
  color: white;
  background: var(--blue);
  font-weight: 900;
  cursor: pointer;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.18);
}

#checkBtn {
  background: var(--green);
}

.success-mark {
  position: absolute;
  z-index: 8;
  left: 50%;
  top: 50%;
  display: grid;
  place-items: center;
  width: min(190px, 42vw);
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  color: #16a34a;
  font-size: clamp(6rem, 18vw, 11rem);
  font-weight: 900;
  line-height: 1;
  transform: translate(-50%, -50%);
  box-shadow: 0 20px 80px rgba(10, 45, 28, 0.28);
}

.corner-actions {
  position: fixed;
  left: 22px;
  bottom: max(22px, env(safe-area-inset-bottom));
  z-index: 6;
}

.corner-actions a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 18px;
  text-decoration: none;
  font-weight: 900;
}

button:active,
.corner-actions a:active {
  transform: translateY(1px);
}

@media (max-width: 720px) {
  .game-shell {
    padding: 6px;
  }

  .fullscreen-button {
    top: 12px;
    right: 12px;
    width: 40px;
    min-height: 40px;
    font-size: 23px;
  }

  .task-grid,
  .frequency-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stats-panel {
    top: 48px;
    right: 9px;
    width: calc(100% - 18px);
    max-height: calc(100dvh - 82px);
    padding: 12px;
  }

  .corner-actions {
    left: 12px;
    bottom: max(12px, env(safe-area-inset-bottom));
  }

  .corner-actions a {
    min-height: 40px;
    padding: 0 14px;
  }
}
