:root {
  color-scheme: light;
  --bg: #f7f8fb;
  --ink: #171a21;
  --muted: #646a76;
  --line: rgba(23, 26, 33, 0.12);
  --panel: rgba(255, 255, 255, 0.92);
  --panel-solid: #ffffff;
  --accent: #2f6df6;
  --accent-strong: #174fd4;
  --success: #13a56f;
  --danger: #e74b55;
  --shadow: 0 12px 32px rgba(22, 27, 36, 0.14);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--ink);
}

body {
  position: fixed;
  inset: 0;
}

button,
input {
  font: inherit;
}

input,
textarea,
select {
  font-size: 16px;
}

button {
  border: 0;
  cursor: pointer;
}

.app {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.86), rgba(247, 248, 251, 0.24) 28%),
    var(--bg);
}

.stage {
  position: absolute;
  inset: 0;
}

#pixelCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
}

.top-bar {
  position: fixed;
  z-index: 10;
  top: max(10px, env(safe-area-inset-top, 0px));
  left: 10px;
  right: 10px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(142px, 0.9fr);
  gap: 8px;
  max-width: 560px;
  margin: 0 auto;
  pointer-events: none;
}

.season-strip,
.brush-strip,
.bottom-panel,
.sheet {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.season-strip,
.brush-strip {
  min-width: 0;
  border-radius: 8px;
  pointer-events: auto;
}

.season-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
}

.status-dot {
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 4px rgba(19, 165, 111, 0.14);
}

.status-dot.ended {
  background: var(--danger);
  box-shadow: 0 0 0 4px rgba(231, 75, 85, 0.14);
}

.label {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.2;
}

strong {
  display: block;
  overflow: hidden;
  font-size: 16px;
  line-height: 1.1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brush-strip {
  padding: 10px 12px;
}

.brush-copy {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 8px;
}

.brush-meter {
  height: 7px;
  margin-top: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(23, 26, 33, 0.1);
}

.brush-meter span {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #2f6df6, #17a673);
  transition: width 180ms ease;
}

.brush-next {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.2;
}

.zoom-hint {
  position: fixed;
  z-index: 6;
  top: 96px;
  left: 50%;
  max-width: calc(100vw - 48px);
  transform: translateX(-50%);
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--muted);
  font-size: 12px;
  opacity: 1;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
  white-space: nowrap;
}

.zoom-hint.hidden {
  opacity: 0;
  transform: translate(-50%, -6px);
}

.bottom-panel {
  position: fixed;
  z-index: 10;
  left: 10px;
  right: 10px;
  bottom: calc(10px + var(--safe-bottom));
  max-width: 560px;
  margin: 0 auto;
  padding: 10px;
  border-radius: 8px;
}

.selected-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  margin-bottom: 9px;
  color: var(--muted);
  font-size: 12px;
}

.selected-swatch {
  width: 22px;
  height: 22px;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(23, 26, 33, 0.16);
}

.coord-readout {
  min-width: 74px;
  text-align: right;
}

#selectedLabel {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.palette {
  display: grid;
  grid-auto-columns: 38px;
  grid-auto-flow: column;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 1px 9px;
  scrollbar-width: none;
}

.palette::-webkit-scrollbar {
  display: none;
}

.color-button {
  position: relative;
  width: 38px;
  height: 38px;
  border: 2px solid rgba(255, 255, 255, 0.98);
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(23, 26, 33, 0.13);
}

.color-button[aria-selected="true"] {
  box-shadow: 0 0 0 3px var(--ink);
}

.color-button[aria-selected="true"]::after {
  position: absolute;
  inset: 10px;
  content: "";
  border: 2px solid rgba(255, 255, 255, 0.96);
  border-radius: 50%;
}

.action-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.tool-button {
  min-height: 42px;
  padding: 0 8px;
  border-radius: 8px;
  background: #eef1f7;
  color: var(--ink);
  font-weight: 700;
}

.tool-button.primary {
  background: var(--accent);
  color: #fff;
}

.toast {
  position: fixed;
  z-index: 30;
  left: 50%;
  bottom: calc(142px + var(--safe-bottom));
  width: max-content;
  max-width: calc(100vw - 42px);
  transform: translate(-50%, 12px);
  padding: 9px 12px;
  border-radius: 8px;
  background: rgba(23, 26, 33, 0.92);
  color: #fff;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.sheet-backdrop {
  position: fixed;
  z-index: 19;
  inset: 0;
  background: rgba(12, 14, 18, 0.28);
}

.modal-backdrop {
  position: fixed;
  z-index: 39;
  inset: 0;
  background: rgba(12, 14, 18, 0.34);
  opacity: 0;
  transition: opacity 160ms ease;
}

.modal-backdrop.open {
  opacity: 1;
}

.name-modal {
  position: fixed;
  z-index: 40;
  left: 18px;
  right: 18px;
  top: 50%;
  max-width: 360px;
  margin: 0 auto;
  transform: translateY(-50%) scale(0.96);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.name-modal.open {
  transform: translateY(-50%) scale(1);
  opacity: 1;
  pointer-events: auto;
}

.name-modal form {
  display: grid;
  gap: 12px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.name-modal h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.15;
}

.name-modal p {
  margin: -4px 0 2px;
  color: var(--muted);
  font-size: 13px;
}

.name-modal input {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #fff;
  color: var(--ink);
  font-size: 16px;
}

.name-modal-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
}

.sheet {
  position: fixed;
  z-index: 20;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: min(76dvh, 620px);
  max-width: 560px;
  margin: 0 auto;
  padding: 10px 16px calc(16px + var(--safe-bottom));
  overflow: auto;
  border-radius: 8px 8px 0 0;
  transform: translateY(108%);
  transition: transform 220ms ease;
}

.sheet.open {
  transform: translateY(0);
}

.sheet-handle {
  width: 42px;
  height: 4px;
  margin: 0 auto 12px;
  border-radius: 999px;
  background: rgba(23, 26, 33, 0.18);
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.sheet-header h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.15;
}

.icon-close {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: #eef1f7;
  color: var(--ink);
  font-size: 24px;
  line-height: 1;
}

.ranking-list {
  display: grid;
  gap: 8px;
}

.rank-row {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 58px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-solid);
}

.rank-row.me {
  border-color: rgba(47, 109, 246, 0.36);
  background: #f0f5ff;
}

.rank-index {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 8px;
  background: #eef1f7;
  font-weight: 800;
}

.rank-name {
  overflow: hidden;
}

.rank-name strong,
.rank-score strong {
  font-size: 14px;
}

.rank-name span,
.rank-score span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.rank-score {
  min-width: 72px;
  text-align: right;
}

.nickname-form {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.nickname-form label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.nickname-form div {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 78px;
  gap: 8px;
}

.nickname-form input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #fff;
  color: var(--ink);
  font-size: 16px;
}

.nickname-form button {
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-weight: 700;
}

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

.stat-grid article {
  min-height: 86px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-solid);
}

.stat-grid span {
  display: block;
  font-size: 26px;
  font-weight: 850;
  line-height: 1;
}

.stat-grid p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.rules-list {
  margin: 0;
  padding-left: 20px;
  color: var(--ink);
}

.rules-list li {
  margin: 0 0 12px;
  line-height: 1.55;
}

@media (min-width: 720px) {
  .top-bar {
    top: 18px;
  }

  .bottom-panel {
    bottom: 18px;
  }

  .zoom-hint {
    top: 104px;
  }
}

@media (max-width: 360px) {
  .top-bar {
    grid-template-columns: 1fr;
  }

  .zoom-hint {
    top: 150px;
  }

  .tool-button {
    font-size: 13px;
  }
}
