:root {
  --bg-1: #ebf1f7;
  --bg-2: #cfdbe9;
  --panel: rgba(255, 255, 255, 0.78);
  --panel-border: rgba(41, 65, 94, 0.14);
  --text-main: #182330;
  --text-muted: #5d6f83;
  --accent: #167c6b;
  --accent-soft: rgba(22, 124, 107, 0.12);
  --shadow: rgba(21, 35, 59, 0.16);
  --viewer-bg-top: #fdfefe;
  --viewer-bg-bottom: #d7e2ee;
  font-family: "Avenir Next", "PingFang SC", "Noto Sans SC", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(86, 145, 223, 0.24), transparent 26%),
    radial-gradient(circle at bottom right, rgba(35, 124, 110, 0.18), transparent 24%),
    linear-gradient(160deg, var(--bg-1), var(--bg-2));
  color: var(--text-main);
}

button {
  font: inherit;
  border: 0;
  border-radius: 14px;
  padding: 10px 14px;
  background: linear-gradient(180deg, #22a68d, #146f60);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  transition:
    transform 140ms ease,
    filter 140ms ease,
    opacity 140ms ease;
}

button:hover {
  transform: translateY(-1px);
  filter: brightness(1.03);
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  cursor: wait;
  opacity: 0.5;
  transform: none;
}

button.ghost {
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid rgba(22, 124, 107, 0.2);
}

.app-shell {
  width: min(1280px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 12px 0 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 100vh;
}

.stage-wrap {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: min(74vh, 860px);
  align-items: center;
}

h1,
h2,
p {
  margin: 0;
}

h2 {
  font-size: 15px;
  color: var(--text-muted);
}

.status-line {
  color: var(--text-muted);
}

.viewer {
  position: relative;
  flex: 1 1 auto;
  min-height: min(74vh, 860px);
  width: 100%;
  border-radius: 28px;
  overflow: hidden;
  touch-action: none;
  background:
    radial-gradient(circle at 50% 16%, rgba(255, 255, 255, 0.88), transparent 28%),
    linear-gradient(180deg, var(--viewer-bg-top), var(--viewer-bg-bottom));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.7),
    0 22px 50px var(--shadow);
}

.viewer::after {
  content: "";
  position: absolute;
  inset: auto 22% 6% 22%;
  height: 16%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(69, 112, 204, 0.18), transparent 70%);
  filter: blur(18px);
  pointer-events: none;
}

.viewer canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 28px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.82),
    0 22px 50px var(--shadow);
  backdrop-filter: blur(18px);
  padding: 14px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.controls {
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  background: rgba(247, 251, 255, 0.48);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.stage-tools {
  width: min(860px, 100%);
  padding: 8px 12px;
}

.stage-tools-row,
.controls-header,
.action-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.stage-tools-row {
  justify-content: center;
  flex-wrap: wrap;
  column-gap: 12px;
  row-gap: 8px;
}

.controls-header {
  justify-content: space-between;
}

.stage-tools-label {
  color: var(--text-muted);
  font-size: 15px;
  font-weight: 700;
  min-width: fit-content;
}

.view-toggle-row {
  display: flex;
  flex-direction: row;
  gap: 8px;
  align-items: center;
}

button.is-active {
  background: linear-gradient(180deg, #167c6b, #0f5f52);
  color: #fff;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.24),
    0 0 0 2px rgba(22, 124, 107, 0.12);
}

.view-toggle-row button,
.tool-actions button {
  min-width: 0;
  padding: 8px 12px;
  border-radius: 12px;
}

.hidden {
  display: none !important;
}

.session-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 10px;
}

.stat-card {
  padding: 10px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.5);
  border: 1px solid rgba(41, 65, 94, 0.08);
  text-align: center;
}

.stat-label {
  display: block;
  color: var(--text-muted);
  font-size: 12px;
}

.stat-value {
  display: block;
  margin-top: 6px;
  font-size: 18px;
  font-weight: 700;
}

.leaderboard-empty {
  margin-top: 10px;
  color: var(--text-muted);
  text-align: center;
}

.leaderboard-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.move-log {
  margin-top: 10px;
  min-height: 42px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.56);
  border: 1px solid rgba(41, 65, 94, 0.08);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.7;
  word-break: break-word;
}

.paint-palette {
  display: grid;
  grid-template-columns: repeat(10, 28px);
  gap: 8px;
}

.paint-swatch {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 10px;
  border: 2px solid rgba(255, 255, 255, 0.6);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.32),
    0 6px 14px rgba(21, 35, 59, 0.12);
  cursor: pointer;
  transition:
    transform 140ms ease,
    box-shadow 140ms ease,
    border-color 140ms ease;
}

.paint-swatch:hover {
  transform: translateY(-1px);
}

.paint-swatch.is-active {
  border-color: #182330;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.32),
    0 0 0 2px rgba(24, 35, 48, 0.16),
    0 8px 18px rgba(21, 35, 59, 0.18);
}

.paint-swatch.is-clear {
  display: grid;
  place-items: center;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.9) 0 46%, rgba(24, 35, 48, 0.14) 46% 54%, rgba(255, 255, 255, 0.9) 54% 100%);
  color: var(--text-main);
  font-size: 10px;
  font-weight: 700;
}

.paint-palette-wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.paint-palette,
.paint-palette-wrap,
.action-row {
  align-items: center;
}

.tool-actions {
  gap: 8px;
  align-items: center;
}

.tool-actions button {
  padding: 8px 12px;
}

.custom-color-input {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 2px solid rgba(255, 255, 255, 0.6);
  border-radius: 10px;
  background: transparent;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.32),
    0 6px 14px rgba(21, 35, 59, 0.12);
  cursor: pointer;
  vertical-align: middle;
  align-self: center;
  appearance: none;
  -webkit-appearance: none;
}

.custom-color-input::-webkit-color-swatch-wrapper {
  padding: 3px;
}

.custom-color-input::-webkit-color-swatch {
  border: 0;
  border-radius: 6px;
}

.paint-swatch:disabled,
.custom-color-input:disabled,
#paint-toggle-button:disabled {
  opacity: 0.42;
  cursor: not-allowed;
  transform: none;
  filter: none;
}

.leaderboard-item {
  display: grid;
  grid-template-columns: 42px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.52);
  border: 1px solid rgba(41, 65, 94, 0.08);
  font-size: 13px;
}

.leaderboard-rank,
.leaderboard-name {
  font-weight: 700;
}

.leaderboard-meta,
.leaderboard-date {
  color: var(--text-muted);
}

.leaderboard-date {
  grid-column: 1 / -1;
}

.counter-card {
  text-align: center;
}

.counter-value {
  font-size: 32px;
  font-weight: 700;
  line-height: 1;
}

.counter-label {
  margin-top: 8px;
  color: var(--text-muted);
  font-size: 13px;
}

@media (max-width: 980px) {
  .app-shell {
    width: calc(100vw - 24px);
    padding: 12px 0;
  }

  .viewer {
    min-height: 420px;
  }

  .stage-tools-row {
    justify-content: center;
  }

  .panel .action-row {
    flex-direction: column;
  }

  .panel button {
    width: 100%;
  }

  .paint-palette-wrap {
    justify-content: center;
  }
}
