:root {
  color-scheme: light dark;
  --bg: #f3efe6;
  --surface: #fffcf5;
  --ink: #23211d;
  --muted: #706858;
  --line: #d5cab6;
  --accent: #2f5d8a;
  --accent-ink: #ffffff;
  --select: #d99a00;
  --tone: #4a6b3a;
  --tension: #b0432f;
  --avoid: #8a8478;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181c;
    --surface: #23252b;
    --ink: #ebe7df;
    --muted: #a19b90;
    --line: #3d4048;
    --accent: #4f86bd;
    --select: #f2c14e;
    --tone: #8cc176;
    --tension: #f08a70;
    --avoid: #7d786f;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  /* 下に固定した操作欄に手札が隠れないよう、その高さぶん余白をとる */
  padding: 0 max(16px, env(safe-area-inset-right)) calc(150px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  /* ダブルタップでの拡大を止めて、連続タップを素直に受け付ける */
  touch-action: manipulation;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: calc(8px + env(safe-area-inset-top));
}

.header-buttons {
  display: flex;
  gap: 6px;
}

h1 {
  margin: 8px 0;
  font-size: 1.4rem;
  letter-spacing: 0.1em;
}

h2 {
  margin: 14px 0 6px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
}

.text-button {
  min-width: 44px;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font-size: 0.9rem;
}

.scoreboard {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 12px;
}

.progression-name {
  margin: 4px 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.scores {
  display: flex;
  gap: 12px;
  margin: 4px 0;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.bars {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-top: 8px;
}

.bar {
  min-height: 92px;
  padding: 6px;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.bar-current {
  border-color: var(--select);
  box-shadow: 0 0 0 2px var(--select);
}

.bar-chord {
  margin: 0 0 4px;
  font-size: 0.95rem;
  font-weight: 700;
  white-space: nowrap;
}

.note-line {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  min-height: 22px;
  margin-top: 3px;
}

.note-line-cpu {
  padding-top: 3px;
  border-top: 1px dashed var(--line);
}

.chip {
  padding: 1px 5px;
  border-radius: 4px;
  color: #ffffff;
  font-size: 0.75rem;
  font-weight: 600;
}

.chip-tone { background: var(--tone); }
.chip-tension { background: var(--tension); }
.chip-avoid { background: var(--avoid); text-decoration: line-through; }
.chip-rest { background: transparent; color: var(--muted); border: 1px solid var(--line); }

.legend {
  display: flex;
  gap: 12px;
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.75rem;
}

.pending {
  min-height: 1.2em;
  margin: 10px 0 0;
  color: var(--tension);
  font-size: 0.85rem;
  font-weight: 600;
}

.log {
  min-height: 2.8em;
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
  white-space: pre-line;
}

.hand {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.note-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  width: 60px;
  height: 84px;
  padding: 0;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  transition: transform 0.15s, box-shadow 0.15s;
}

.note-card[aria-pressed='true'] {
  border-color: var(--select);
  box-shadow: 0 0 0 3px var(--select);
  transform: translateY(-4px);
}

.note-card:disabled {
  opacity: 0.6;
}

.note-name {
  font-size: 1.5rem;
  font-weight: 700;
}

.note-role {
  font-size: 0.8rem;
  font-weight: 600;
}

.role-tone { color: var(--tone); }
.role-tension { color: var(--tension); }
.role-avoid { color: var(--avoid); text-decoration: line-through; }

.note-order {
  position: absolute;
  top: -8px;
  right: -8px;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--select);
  color: #23211d;
  font-size: 0.8rem;
  font-weight: 700;
}

.action-bar {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  padding: 10px max(16px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.hint {
  min-height: 1.2em;
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.85rem;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.action {
  min-height: 44px;
  padding: 0 16px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 1rem;
  font-weight: 600;
}

.action:disabled {
  opacity: 0.45;
}

.action-minor {
  margin-left: auto;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  font-weight: 400;
}

dialog {
  max-width: min(480px, calc(100vw - 32px));
  max-height: calc(100dvh - 48px);
  padding: 20px;
  border: none;
  border-radius: 14px;
  background: var(--surface);
  color: var(--ink);
  line-height: 1.6;
}

dialog::backdrop {
  background: rgb(0 0 0 / 0.45);
}

.dialog-title {
  margin-top: 0;
  color: var(--ink);
  font-size: 1.2rem;
}

dialog ul {
  padding-left: 1.2em;
}

.tip {
  color: var(--muted);
  font-size: 0.9rem;
}

.dialog-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.dialog-buttons-wrap {
  flex-wrap: wrap;
}

@media (prefers-reduced-motion: reduce) {
  .note-card[aria-pressed='true'] {
    transform: none;
  }
}

dialog h3 {
  margin: 14px 0 4px;
  font-size: 0.95rem;
}

dialog ol,
dialog ul {
  margin: 4px 0;
  padding-left: 1.4em;
}
