:root {
  --bg: #f1ebe1;
  --paper: #faf6ef;
  --ink: #1a1612;
  --muted: #6d645a;
  --line: #d4c7b4;
  --ink-line: #2a241c;
  --accent: #c2410c;
  --accent-soft: #f4d4c4;
  --given: #1a1612;
  --entry: #1e3a5f;
  --select: #f3d9a4;
  --peer: #eee4d2;
  --same: #e6c57a;
  --error: #b42318;
  --ok: #2f6b45;
  --shadow: 0 18px 50px rgba(40, 28, 14, 0.12);
  --radius: 18px;
  --pad: 16px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #12100e;
  --paper: #1c1916;
  --ink: #f4efe6;
  --muted: #b5a99a;
  --line: #3f372e;
  --ink-line: #f4efe6;
  --accent: #e86f3a;
  --accent-soft: #3a241c;
  --given: #f4efe6;
  --entry: #9ec3ea;
  --select: #4a3820;
  --peer: #2a241c;
  --same: #6d5224;
  --error: #ff7a70;
  --ok: #7dcea0;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  height: 100%;
  height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Hiragino Sans", "Yu Gothic UI", "Noto Sans JP", sans-serif;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

body {
  background-image:
    radial-gradient(1200px 500px at 50% -120px, color-mix(in srgb, var(--accent) 12%, transparent), transparent 60%),
    linear-gradient(180deg, color-mix(in srgb, var(--paper) 55%, var(--bg)), var(--bg));
}

button,
select {
  font: inherit;
  color: inherit;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

select {
  font-size: 16px;
}

#app {
  width: min(560px, 100%);
  height: 100%;
  margin: 0 auto;
  padding: calc(10px + env(safe-area-inset-top)) var(--pad) calc(12px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

.top-actions {
  display: flex;
  gap: 8px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  flex-shrink: 0;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.brand h1 {
  margin: 0;
  font-family: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", serif;
  font-size: 24px;
  font-weight: 600;
  letter-spacing: 0.18em;
}

.brand small {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.08em;
}

.icon-btn,
.ghost-btn,
.primary-btn,
.pad-btn {
  border: 0;
  background: var(--paper);
  cursor: pointer;
  transition: transform 0.12s ease, background 0.12s ease, box-shadow 0.12s ease;
}

.icon-btn:active,
.ghost-btn:active,
.primary-btn:active,
.pad-btn:active,
.cell:active {
  transform: scale(0.97);
}

.icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
  flex-shrink: 0;
}

.chip,
.select-wrap {
  background: var(--paper);
  border-radius: 999px;
  box-shadow: var(--shadow);
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  padding: 0 14px;
  font-variant-numeric: tabular-nums;
}

.select-wrap {
  padding-right: 8px;
}

.select-wrap select {
  border: 0;
  background: transparent;
  outline: none;
  padding: 8px 4px;
}

#timer {
  letter-spacing: 0.06em;
  font-weight: 600;
}

.primary-btn {
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  padding: 0 14px;
  min-height: 40px;
  font-weight: 700;
  box-shadow: var(--shadow);
  white-space: nowrap;
}

.board-wrap {
  background: var(--paper);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow);
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.board {
  --cell: 36px;
  display: grid;
  grid-template-columns: repeat(3, calc(var(--cell) * 3 + 2px));
  grid-template-rows: repeat(3, calc(var(--cell) * 3 + 2px));
  gap: 3px;
  width: calc(var(--cell) * 9 + 18px);
  height: calc(var(--cell) * 9 + 18px);
  margin: 0 auto;
  border: 3px solid var(--ink-line);
  background: var(--ink-line);
  overflow: hidden;
  min-width: 0;
  min-height: 0;
}

.box {
  display: grid;
  grid-template-columns: repeat(3, var(--cell));
  grid-template-rows: repeat(3, var(--cell));
  gap: 1px;
  min-width: 0;
  min-height: 0;
  background: var(--line);
}

.cell {
  position: relative;
  appearance: none;
  -webkit-appearance: none;
  box-sizing: border-box;
  border: 0;
  border-radius: 0;
  background: var(--paper);
  padding: 0;
  margin: 0;
  width: var(--cell);
  height: var(--cell);
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  display: grid;
  place-items: center;
  font-family: "Iowan Old Style", "Hiragino Mincho ProN", Georgia, serif;
  font-size: clamp(16px, calc(var(--cell) * 0.52), 28px);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--entry);
  line-height: 1;
}

.cell.given {
  color: var(--given);
  font-weight: 700;
}

.cell.peer {
  background: var(--peer);
}

.cell.same {
  background: var(--same);
}

.cell.selected {
  background: var(--select);
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  z-index: 1;
}

.cell.error {
  color: var(--error);
}

.cell.hinted {
  color: var(--ok);
}

.notes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  width: 92%;
  height: 92%;
  font-size: clamp(8px, 2.1vw, 11px);
  font-weight: 600;
  color: var(--muted);
  pointer-events: none;
}

.notes span {
  display: grid;
  place-items: center;
  opacity: 0;
}

.notes span.on {
  opacity: 1;
}

.controls {
  margin-top: 12px;
  display: grid;
  gap: 8px;
  flex-shrink: 0;
}

.actions,
.pad {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.pad {
  grid-template-columns: repeat(9, 1fr);
}

.pad-btn {
  min-height: 48px;
  min-width: 0;
  border-radius: 14px;
  box-shadow: var(--shadow);
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  position: relative;
}

.ghost-btn {
  min-height: 44px;
  border-radius: 14px;
  box-shadow: var(--shadow);
  font-size: 13px;
  font-weight: 700;
}

.pad-btn.done {
  opacity: 0.35;
}

.pad-btn .rest {
  position: absolute;
  right: 4px;
  top: 3px;
  font-size: 9px;
  color: var(--muted);
  font-weight: 600;
}

.ghost-btn.active {
  background: var(--accent);
  color: #fff;
}

.overlay,
.toast {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  background: color-mix(in srgb, var(--ink) 28%, transparent);
  padding: 20px;
  z-index: 20;
}

.overlay.open {
  display: grid;
}

.overlay[hidden] {
  display: none !important;
}

.modal,
.toast-card {
  width: min(420px, 100%);
  background: var(--paper);
  color: var(--ink);
  border-radius: 22px;
  padding: 22px;
  box-shadow: var(--shadow);
  text-align: center;
}

.modal h2,
.toast-card h2 {
  margin: 0 0 8px;
  font-family: "Hiragino Mincho ProN", "Yu Mincho", serif;
  letter-spacing: 0.12em;
}

.modal p,
.toast-card p {
  margin: 0 0 16px;
  color: var(--muted);
}

.modal-actions {
  display: grid;
  gap: 8px;
}

.settings {
  text-align: left;
  display: grid;
  gap: 10px;
  margin: 14px 0 18px;
}

.setting {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.setting:last-child {
  border-bottom: 0;
}

.status-row {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
  margin-top: 8px;
  padding: 0 4px;
  flex-shrink: 0;
}

.install-banner {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  background: var(--paper);
  color: var(--ink);
  border-radius: 18px;
  padding: 14px;
  box-shadow: var(--shadow);
  z-index: 15;
}

.install-banner[hidden] {
  display: none;
}

.install-banner p {
  margin: 0 0 10px;
  font-size: 14px;
}

.install-banner-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.install-steps {
  text-align: left;
  margin: 0 0 14px;
  padding-left: 1.2em;
  color: var(--ink);
}

.install-steps li {
  margin: 8px 0;
}

.install-url {
  font-weight: 700;
  word-break: break-all;
  color: var(--ink) !important;
}

@media (min-width: 820px) {
  html,
  body {
    height: auto;
    min-height: 100dvh;
    overflow: auto;
  }

  #app {
    width: min(980px, 100%);
    height: auto;
    min-height: 100dvh;
    display: grid;
    grid-template-columns: 1fr 320px;
    grid-template-rows: auto auto 1fr;
    gap: 0 28px;
    overflow: visible;
  }

  .brand h1 {
    font-size: 28px;
  }

  .topbar,
  .toolbar {
    grid-column: 1 / -1;
  }

  .board-wrap {
    align-self: start;
    flex: none;
  }

  .controls {
    margin-top: 0;
    align-self: start;
  }

  .pad {
    grid-template-columns: repeat(3, 1fr);
  }

  .pad-btn {
    min-height: 64px;
    font-size: 26px;
  }
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 8px auto 14px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

