:root {
  color-scheme: light;
  --bg: #f9f7f2;
  --card: #ffffff;
  --text: #1c1c1c;
  --muted: #6d6d6d;
  --accent: #1f7a7a;
  --accent-soft: #d8f0f0;
  --danger: #d94d4d;
  --border: #e4dfd3;
  --shadow: 0 15px 40px rgba(31, 122, 122, 0.08);
}

[data-theme='dark'] {
  color-scheme: dark;
  --bg: #101717;
  --card: #152020;
  --text: #f4f7f7;
  --muted: #99a5a5;
  --accent: #68d3c6;
  --accent-soft: rgba(104, 211, 198, 0.1);
  --danger: #ff7a7a;
  --border: #233131;
  --shadow: 0 15px 40px rgba(0, 0, 0, 0.25);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Zen Kaku Gothic New', 'Hiragino Sans', 'Noto Sans JP',
    sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

img {
  max-width: 100%;
  display: block;
}

.app-shell {
  min-height: 100vh;
  padding: 24px clamp(16px, 5vw, 48px) 48px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

main {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 16px;
}

.app-header h1 {
  margin: 0;
  font-size: clamp(24px, 4vw, 40px);
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  letter-spacing: 0.08em;
  font-size: 14px;
}

.header-actions {
  display: flex;
  gap: 12px;
}

button {
  border: none;
  border-radius: 999px;
  font-size: 16px;
  padding: 10px 18px;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.2s, box-shadow 0.2s;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
}

button:active {
  transform: scale(0.98);
}

button.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 10px 20px rgba(31, 122, 122, 0.2);
}

button.primary.icon {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

button.ghost {
  background: transparent;
  color: var(--text);
}

button.danger {
  background: var(--danger);
  border-color: var(--danger);
  color: white;
}

.chip-group {
  display: inline-flex;
  background: var(--card);
  border-radius: 999px;
  padding: 4px;
  border: 1px solid var(--border);
  gap: 4px;
}

.chip {
  border-radius: 999px;
  border: none;
  padding: 8px 14px;
  font-size: 14px;
  background: transparent;
  color: var(--muted);
}

.chip.is-active {
  background: var(--accent);
  color: #fff;
}

.scoreboard {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.team-summary-list {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  overflow-y: visible;
  padding: 6px 0;
}

.team-summary-list::-webkit-scrollbar {
  height: 6px;
}

.team-summary-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 999px;
}

.team-summary {
  border-radius: 18px;
  border: 1px solid var(--border);
  padding: 16px 20px;
  background: var(--card);
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 160px;
  text-align: left;
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.2s;
}

.team-summary.is-active {
  border-color: var(--accent);
  box-shadow: 0 8px 20px rgba(31, 122, 122, 0.12);
  transform: translateY(-2px);
}

.team-summary__name {
  font-size: 13px;
  color: var(--muted);
  margin: 0;
}

.team-summary__score {
  font-size: 24px;
  font-weight: 700;
  margin: 0;
  color: var(--text);
}

.team-summary__meta {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  gap: 6px;
}

.team-summary__badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(217, 77, 77, 0.1);
  color: var(--danger);
}

.team-detail {
  min-height: 200px;
}

.team-detail-card {
  gap: 16px;
}

.team-detail__content {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.team-detail__meta-block {
  width: 100%;
  display: flex;
  justify-content: flex-end;
}

.team-detail__chips {
  display: flex;
  gap: 8px;
  flex-wrap: nowrap;
  align-items: stretch;
  overflow-x: auto;
  padding-bottom: 2px;
}

.team-detail__chips::-webkit-scrollbar {
  height: 3px;
}

.team-detail__chips::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 999px;
}

.meta-chip {
  border-radius: 16px;
  padding: 4px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 10px;
  display: inline-flex;
  align-items: baseline;
  gap: 3px;
  color: var(--muted);
  white-space: nowrap;
}

.meta-chip strong {
  font-size: 14px;
  color: var(--text);
}

.team-detail__set-button {
  width: 100%;
  padding: 8px 12px;
}

.team-card {
  background: var(--card);
  border-radius: 24px;
  padding: 26px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.team-card__head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: flex-start;
  font-size: 14px;
}

.team-card label {
  display: block;
  font-size: 13px;
  color: var(--muted);
}

.team-name {
  display: block;
  width: 180px;
  border: none;
  border-bottom: 1px dashed var(--border);
  background: transparent;
  color: var(--text);
  font-size: 18px;
  padding: 4px 0;
}

.team-card__score {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.score {
  font-size: clamp(48px, 9vw, 64px);
  font-weight: 700;
}

.target {
  font-size: 16px;
  color: var(--muted);
}

.team-card__meta {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.team-card__meta strong {
  display: block;
  color: var(--text);
  font-size: 18px;
}

.badge {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--accent);
  white-space: nowrap;
  visibility: hidden;
}

.badge.is-active {
  visibility: visible;
}

.team-card__actions {
  display: flex;
  justify-content: flex-end;
}

.team-card__set-button {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: rgba(31, 122, 122, 0.4);
  font-weight: 600;
  padding: 8px 18px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.04);
}

.team-card__set-button:hover {
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
  border-color: var(--accent);
}

.team-log {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.team-log__title {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

.team-log__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 180px;
  overflow-y: auto;
}

.team-log__item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-size: 13px;
}

.team-log__delta {
  font-weight: 700;
  color: var(--accent);
  min-width: 44px;
}

.team-log__delta.is-negative {
  color: var(--danger);
}

.team-log__delta.is-neutral {
  color: var(--muted);
}

.team-log__body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.team-log__text {
  margin: 0;
  color: var(--text);
}

.team-log__meta {
  font-size: 11px;
  color: var(--muted);
}

.team-log__empty {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.pad {
  background: var(--card);
  border-radius: 32px;
  padding: 24px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.pad__selectors {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  font-size: 13px;
  color: var(--muted);
  row-gap: 8px;
}

.pad__selectors > div > p {
  margin: 0 0 4px;
}

.pad__keys-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}

.pad__keys-row {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.pad__miss {
  display: flex;
  justify-content: center;
}

.pad__keys-grid button {
  border-radius: 18px;
  height: 60px;
  font-size: 19px;
  font-weight: 600;
  background: linear-gradient(135deg, #f9f2e4, #ead8bb);
  border: 1px solid #d7c2a2;
  box-shadow:
    inset 0 -3px 0 #c9b18f,
    0 3px 6px rgba(92, 59, 26, 0.12);
  color: #5c3b1a;
  min-width: 72px;
}

.pad__keys-grid button.is-selected {
  border-color: var(--accent);
  box-shadow:
    inset 0 -3px 0 rgba(31, 122, 122, 0.4),
    0 3px 10px rgba(31, 122, 122, 0.2);
}

.pad__keys-grid button:active {
  transform: translateY(1px);
  box-shadow:
    inset 0 -1px 0 #b79976,
    0 1px 3px rgba(92, 59, 26, 0.12);
}

.pad__keys-grid button[data-value='0'] {
  background: linear-gradient(135deg, #eceff4, #d9e0ea);
  border-color: #c3d0e3;
  color: #2f4858;
}

.pad__multi-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 8px 4px 0;
}

.pad__multi-controls[hidden] {
  display: none;
}

.pad__multi-count {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

.pad__multi-buttons {
  display: flex;
  gap: 8px;
}

.pad__actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.pad__actions button {
  min-width: 140px;
}

.pad__miss-button {
  min-width: auto;
  padding: 8px 16px;
}

.reset-section {
  margin-top: 24px;
  padding: 24px;
  border-radius: 28px;
  background: var(--card);
  border: 2px dashed var(--border);
  box-shadow: var(--shadow);
}

.reset-section__header {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 20px;
}

.reset-section__header h3 {
  margin: 0;
}

.reset-section__header p {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

.reset-panels {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.reset-card {
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 16px;
  background: var(--bg);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.reset-card button {
  font-size: 14px;
}

.reset-card h3 {
  margin: 0;
  font-size: 16px;
}

.reset-card p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.status-panel {
  background: var(--card);
  border-radius: 20px;
  padding: 16px 20px;
  border: 1px dashed var(--border);
}

.status-text {
  margin: 0;
  font-size: 14px;
  color: var(--muted);
}

@media (min-width: 1024px) {
  main {
    display: grid;
    grid-template-columns: minmax(0, 1.1fr) minmax(320px, 0.9fr);
    gap: 24px;
    align-items: start;
  }

  .status-panel {
    grid-column: span 2;
  }
}

@media (max-width: 600px) {
  .app-shell {
    padding: 16px 12px 32px;
    gap: 16px;
  }

  .overlay__panel {
    width: 92vw;
    padding: 20px;
    max-height: 70vh;
  }

  .team-summary {
    padding: 8px 12px;
    min-width: 120px;
  }

  .team-card {
    padding: 16px;
    border-radius: 20px;
  }

  .team-detail__content {
    display: flex;
    flex-direction: column;
    gap: 12px;
  }

  .team-detail__meta-block {
    width: 100%;
    justify-content: flex-start;
    margin-top: 8px;
  }

  .team-detail__set-button {
    width: 100%;
  }

  .score {
    font-size: 48px;
  }

  .team-card__meta {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .pad {
    padding: 16px;
    border-radius: 24px;
    gap: 16px;
  }

  .pad__keys-grid button {
    height: 56px;
    font-size: 18px;
  }

  .reset-section {
    margin-top: 16px;
    padding: 16px;
  }

  .status-panel {
    padding: 12px 16px;
  }
}

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.overlay[hidden] {
  display: none;
}

.overlay__backdrop {
  position: absolute;
  inset: 0;
  backdrop-filter: blur(4px);
  background: rgba(0, 0, 0, 0.35);
}

.overlay__panel,
.tutorial-panel {
  position: relative;
  background: var(--card);
  color: var(--text);
  padding: 24px;
  border-radius: 24px;
  width: min(420px, 90vw);
  max-height: 75vh;
  overflow: hidden;
  box-shadow: var(--shadow);
  z-index: 1;
}

.tutorial-panel {
  width: min(560px, 96vw);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.overlay__panel header,
.tutorial-panel header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.overlay__panel h2,
.tutorial-panel h2 {
  margin: 0;
}

#settingsForm {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-height: calc(75vh - 90px);
  overflow-y: auto;
  padding-right: 8px;
  margin-right: -8px;
}

#settingsForm label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
  color: var(--muted);
}

#settingsForm label small {
  font-size: 12px;
  color: var(--muted);
}

#settingsForm input,
#settingsForm select {
  border-radius: 14px;
  border: 1px solid var(--border);
  padding: 10px 14px;
  font-size: 16px;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

.settings-section {
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
}

.settings-section legend {
  padding: 0 8px;
  font-weight: 600;
}

.settings-note {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--muted);
}

.team-settings {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 10px;
}

.team-setting-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
}

.team-setting-row__label {
  min-width: 56px;
  font-size: 14px;
  color: var(--muted);
}

.team-setting-row input {
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 8px 12px;
  font-size: 15px;
  background: var(--bg);
  color: var(--text);
  min-width: 0;
}

.team-setting-row button {
  border-radius: 12px;
  padding: 6px 12px;
  white-space: nowrap;
}

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

.tutorial-slider {
  position: relative;
  overflow: hidden;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--bg);
  aspect-ratio: 4 / 3;
  width: 100%;
}

.tutorial-caption {
  margin: 8px 0 0;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
}

.slides {
  display: flex;
  transition: transform 0.3s ease;
  height: 100%;
}

.slides img {
  width: 100%;
  height: 100%;
  flex-shrink: 0;
  object-fit: contain;
  background: var(--card);
}

.slider-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.3);
  color: #fff;
  font-size: 28px;
}

.slider-nav.prev {
  left: 12px;
}

.slider-nav.next {
  right: 12px;
}

.tutorial-progress {
  display: flex;
  justify-content: center;
  gap: 6px;
}

.tutorial-progress button {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  padding: 0;
  border: none;
  background: var(--border);
}

.tutorial-progress button.is-active {
  background: var(--accent);
}

.tutorial-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
}


@media (min-width: 900px) {
  .pad__keys-row {
    justify-content: center;
  }
}
