:root {
  color: var(--ui-text, #182230);
  background: var(--ui-bg, #eef2f6);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  --panel: var(--ui-surface, #ffffff);
  --panel-soft: var(--ui-surface-soft, #f7f9fc);
  --ink: var(--ui-text, #182230);
  --muted: var(--ui-muted, #647184);
  --line: var(--ui-border, #d6dde7);
  --accent: var(--ui-accent, #2563eb);
  --accent-dark: var(--ui-accent-hover, #1d4ed8);
  --focus: #eff5ff;
  --danger: var(--ui-danger, #c83832);
  --shadow: var(--ui-shadow, 0 8px 28px rgba(32, 48, 70, 0.09));
  --r18: #ff4fc8;
  --r18-dark: #c82489;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--ui-bg, #eef2f6);
}

button,
input {
  font: inherit;
}

button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  font-weight: 750;
  transition:
    border-color 160ms ease,
    background 160ms ease,
    color 160ms ease,
    transform 160ms ease;
}

button:hover {
  border-color: #9eabc0;
  transform: translateY(-1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

h1,
h2,
p {
  margin: 0;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(340px, 410px) minmax(0, 1fr);
  min-height: calc(100vh - var(--toolbar-height, 66px));
  background: var(--ui-bg, #eef2f6);
}

.settings-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px;
  border-right: 1px solid var(--line);
  background: var(--panel-soft);
  overflow-y: auto;
}

.brand {
  display: grid;
  gap: 6px;
  padding: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.brand-description {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.65;
}

.eyebrow {
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1 {
  font-size: 28px;
  letter-spacing: -0.035em;
  line-height: 1.12;
}

h2 {
  margin-bottom: 10px;
  font-size: 13px;
  letter-spacing: 0;
}

.dropzone {
  display: grid;
  place-items: center;
  min-height: 118px;
  padding: 18px;
  border: 1px dashed #a8b5c8;
  border-radius: 10px;
  background: var(--panel);
  text-align: center;
  cursor: pointer;
  transition:
    border-color 160ms ease,
    background 160ms ease;
}

.dropzone.compact {
  min-height: 86px;
  padding: 14px;
}

.dropzone input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.dropzone span {
  display: block;
  font-size: 16px;
  font-weight: 850;
}

.dropzone small {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.dropzone.is-dragging,
.canvas-frame.is-dragging {
  border-color: var(--accent);
  background: var(--focus);
}

.file-name,
.error-text {
  font-size: 13px;
  overflow-wrap: anywhere;
}

.file-name {
  color: var(--muted);
}

.error-text {
  color: var(--danger);
  font-weight: 750;
}

.meta-text {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.control-group {
  padding: 15px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 5px 18px rgba(32, 48, 70, 0.06);
}

.segmented,
.segmented-grid {
  display: grid;
  gap: 8px;
}

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

.segmented-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.difficulty-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.segmented button,
.segmented-grid button {
  padding: 8px 10px;
  font-size: 13px;
  font-weight: 800;
}

button.is-active {
  border-color: var(--accent);
  background: var(--focus);
  color: var(--accent-dark);
}

.share-rating button[data-value="r18"].is-active {
  color: var(--r18-dark);
  background: #fff0fa;
  border-color: var(--r18);
}

.share-rating-group[data-rating="r18"] {
  border-color: rgba(255, 79, 200, 0.55);
  box-shadow: 0 5px 18px rgba(255, 79, 200, 0.12);
}

.share-rating-group[data-rating="r18"] h2,
.share-rating-group[data-rating="r18"] .meta-text {
  color: var(--r18-dark);
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 34px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 650;
}

.toggle-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.stats-panel {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.stats-panel div {
  display: grid;
  gap: 4px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.stats-panel span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
}

.stats-panel strong {
  font-size: 17px;
  font-variant-numeric: tabular-nums;
}

.action-stack {
  display: grid;
  gap: 10px;
  margin-top: auto;
  padding: 15px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.primary-button {
  min-height: 48px;
  border: 0;
  background: var(--accent);
  color: #ffffff;
  font-size: 15px;
  font-weight: 900;
}

.primary-button:hover {
  background: var(--accent-dark);
}

.share-button {
  color: #ffffff;
  background: var(--accent);
  border-color: var(--accent);
}

.share-button:hover {
  color: #ffffff;
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

.share-button.is-r18 {
  color: #ffffff;
  background: var(--r18);
  border-color: var(--r18);
}

.share-button.is-r18:hover {
  background: var(--r18-dark);
  border-color: var(--r18-dark);
}

.game-stage {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 18px;
  min-width: 0;
  padding: 22px;
  overflow: hidden;
}

.stage-toolbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.stage-toolbar h2 {
  margin: 0;
  font-size: 23px;
  line-height: 1.18;
}

.stage-toolbar span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  text-align: right;
}

.canvas-frame {
  position: relative;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background:
    linear-gradient(45deg, rgba(36, 42, 38, 0.06) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(36, 42, 38, 0.06) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(36, 42, 38, 0.06) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(36, 42, 38, 0.06) 75%);
  background-color: #f7f9fc;
  background-position:
    0 0,
    0 12px,
    12px -12px,
    -12px 0;
  background-size: 24px 24px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 540px;
  touch-action: none;
}

.empty-state {
  position: absolute;
  inset: 50% auto auto 50%;
  display: grid;
  width: min(420px, calc(100% - 36px));
  gap: 8px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.9);
  text-align: center;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.empty-state strong {
  font-size: 18px;
}

.empty-state span {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.empty-state[hidden] {
  display: none;
}

.completion-panel {
  position: absolute;
  inset: 50% auto auto 50%;
  display: grid;
  width: min(360px, calc(100% - 36px));
  gap: 8px;
  place-items: center;
  padding: 28px;
  border: 1px solid rgba(37, 99, 235, 0.3);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 22px 60px rgba(23, 30, 27, 0.2);
  color: var(--ink);
  text-align: center;
  transform: translate(-50%, -50%);
  z-index: 4;
}

.completion-panel[hidden] {
  display: none;
}

.completion-panel span {
  color: var(--accent);
  font-size: 14px;
  font-weight: 900;
}

.completion-panel strong {
  font-size: 38px;
  font-variant-numeric: tabular-nums;
}

.completion-panel small,
.completion-panel em {
  color: var(--muted);
  font-size: 14px;
  font-style: normal;
  font-weight: 700;
}

.flash-layer {
  position: absolute;
  inset: 0;
  background: #ffffff;
  opacity: 0;
  pointer-events: none;
  z-index: 5;
}

.flash-layer.is-flashing {
  animation: flash-out 620ms ease forwards;
}

@keyframes flash-out {
  0% {
    opacity: 0;
  }

  18% {
    opacity: 1;
  }

  100% {
    opacity: 0;
  }
}

@media (max-width: 920px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .settings-panel {
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .game-stage {
    min-height: 72vh;
    padding: 14px;
  }
}

@media (max-width: 560px) {
  .settings-panel {
    padding: 18px;
  }

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

  .stage-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .stage-toolbar span {
    text-align: left;
  }

  canvas {
    min-height: 620px;
  }
}
