:root {
  color-scheme: dark;
  --ink: #f4f6ff;
  --muted: #aab7d3;
  --muted-strong: #cbd5ef;
  --panel: rgba(18, 29, 58, 0.9);
  --panel-soft: rgba(20, 33, 67, 0.7);
  --panel-border: rgba(153, 177, 255, 0.2);
  --accent: #8d9bff;
  --accent-strong: #6676ff;
  --board: #071129;
  --danger: #ff9eaa;
  --shadow: 0 24px 60px rgba(2, 7, 24, 0.32);
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
  min-width: 320px;
  overflow: hidden;
  background: #090f22;
}

body {
  height: 100%;
  min-height: 100%;
  min-width: 320px;
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 10%, rgba(106, 124, 255, 0.24), transparent 28rem),
    radial-gradient(circle at 90% 85%, rgba(74, 207, 181, 0.15), transparent 25rem),
    #090f22;
  font-family: "Segoe UI", "Noto Sans JP", system-ui, -apple-system, sans-serif;
  line-height: 1.45;
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
}

button,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

input {
  -webkit-user-select: text;
  user-select: text;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid #f8d66d;
  outline-offset: 3px;
}

button:disabled {
  cursor: wait;
  opacity: 0.58;
}

[hidden] {
  display: none !important;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

.app-shell {
  width: min(100%, 1200px);
  height: 100vh;
  height: 100dvh;
  min-height: 320px;
  margin: 0 auto;
  padding: clamp(8px, 2vh, 20px) clamp(10px, 3vw, 32px) clamp(6px, 1.5vh, 14px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: clamp(5px, 1.2vh, 14px);
  overflow: hidden;
}

.site-header,
.page-footer {
  flex: 0 0 auto;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 24px;
  color: #aeb8ff;
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.14em;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.brand-icon {
  display: grid;
  width: 20px;
  height: 20px;
  place-items: center;
  border: 1px solid rgba(201, 208, 255, 0.42);
  border-radius: 6px;
  color: #f9d276;
  background: rgba(141, 155, 255, 0.15);
  font-size: 0.72rem;
}

.site-tag {
  color: #7382a5;
  font-size: 0.58rem;
  letter-spacing: 0.12em;
}

.screen {
  min-height: 0;
  overflow: hidden;
}

.eyebrow {
  margin: 0 0 5px;
  color: #aeb8ff;
  font-size: clamp(0.56rem, 1vw, 0.72rem);
  font-weight: 800;
  letter-spacing: 0.16em;
}

.title-screen {
  display: grid;
  place-items: center;
}

.title-card {
  width: min(100%, 960px);
  max-height: 100%;
  padding: clamp(16px, 3vw, 34px);
  overflow: hidden;
  border: 1px solid var(--panel-border);
  border-radius: clamp(18px, 3vw, 28px);
  background:
    linear-gradient(135deg, rgba(42, 56, 111, 0.2), transparent 45%),
    var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.title-copy {
  max-width: 760px;
}

.title-copy h1 {
  margin: 0;
  color: #ffffff;
  font-size: clamp(2rem, 6vw, 4.4rem);
  letter-spacing: -0.08em;
  line-height: 0.98;
}

.title-copy h1 span {
  display: block;
  margin-top: 9px;
  color: #aeb8ff;
  font-size: 0.34em;
  font-weight: 700;
  letter-spacing: 0.05em;
}

.title-lead {
  max-width: 600px;
  margin: clamp(10px, 2vh, 18px) 0 0;
  color: var(--muted-strong);
  font-size: clamp(0.78rem, 1.6vw, 1rem);
}

.title-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(7px, 1.2vw, 12px);
  max-width: 620px;
  margin-top: clamp(14px, 2.5vh, 24px);
}

.primary-button,
.secondary-button,
.quiet-button,
.control-button,
.ranking-refresh {
  border: 1px solid rgba(185, 197, 255, 0.24);
  border-radius: 12px;
  color: var(--ink);
  cursor: pointer;
  touch-action: none;
  transition: transform 140ms ease, background 140ms ease, border-color 140ms ease;
}

.primary-button,
.secondary-button {
  min-height: 42px;
  padding: 9px 15px;
  font-weight: 800;
}

.primary-button {
  border-color: transparent;
  background: linear-gradient(135deg, #8996ff, #596aff);
  box-shadow: 0 8px 18px rgba(72, 87, 224, 0.3);
}

.primary-button:hover {
  background: linear-gradient(135deg, #a0aaff, #6f7dff);
}

.secondary-button {
  background: rgba(83, 103, 183, 0.2);
}

.secondary-button:hover,
.quiet-button:hover,
.ranking-refresh:hover {
  border-color: rgba(185, 197, 255, 0.55);
  background: rgba(100, 122, 219, 0.32);
}

.primary-button:active,
.secondary-button:active,
.quiet-button:active,
.control-button:active,
.ranking-refresh:active {
  transform: translateY(1px) scale(0.98);
}

.rules-panel {
  margin-top: clamp(16px, 3vh, 28px);
  padding: clamp(12px, 2vw, 20px);
  border: 1px solid rgba(153, 177, 255, 0.14);
  border-radius: 18px;
  background: rgba(4, 10, 29, 0.22);
}

.section-heading,
.ranking-card-heading,
.ranking-topbar,
.game-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.section-heading h2,
.ranking-card-heading h3 {
  margin: 0;
  color: #ffffff;
  font-size: clamp(1rem, 2vw, 1.35rem);
}

.section-heading .eyebrow {
  margin-bottom: 3px;
}

.section-badge {
  padding: 4px 8px;
  border: 1px solid rgba(185, 197, 255, 0.2);
  border-radius: 999px;
  color: #bfc8ff;
  background: rgba(141, 155, 255, 0.1);
  font-size: 0.58rem;
  font-weight: 800;
  letter-spacing: 0.1em;
}

.rules-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(7px, 1.2vw, 14px);
  margin-top: 14px;
}

.rule-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 9px;
  align-items: start;
  padding: 11px;
  border: 1px solid rgba(153, 177, 255, 0.1);
  border-radius: 12px;
  background: rgba(20, 33, 67, 0.45);
}

.rule-number {
  color: #f9d276;
  font-size: 0.7rem;
  font-weight: 900;
  letter-spacing: 0.05em;
}

.rule-item h3,
.operation-guide h3 {
  margin: 0 0 3px;
  color: #dce3ff;
  font-size: clamp(0.7rem, 1.3vw, 0.82rem);
}

.rule-item p,
.operation-guide p {
  margin: 0;
  color: var(--muted);
  font-size: clamp(0.62rem, 1.15vw, 0.75rem);
}

.operation-guides {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(7px, 1.2vw, 14px);
  margin-top: 12px;
}

.operation-guide {
  padding: 10px 11px;
  border-top: 1px solid rgba(153, 177, 255, 0.14);
}

kbd {
  display: inline-block;
  min-width: 1.55em;
  margin-right: 2px;
  padding: 1px 4px;
  border: 1px solid rgba(190, 201, 255, 0.28);
  border-bottom-width: 2px;
  border-radius: 5px;
  color: #f2f4ff;
  background: rgba(4, 10, 29, 0.4);
  font-size: 0.68rem;
  text-align: center;
}

.danger-note {
  margin: 11px 0 0;
  padding: 8px 10px;
  border-left: 3px solid var(--danger);
  color: #bbc7e4;
  background: rgba(255, 125, 145, 0.08);
  font-size: clamp(0.62rem, 1.1vw, 0.74rem);
}

.danger-note strong {
  color: #ffb2bd;
}

.game-screen {
  display: flex;
  flex-direction: column;
  min-height: 0;
  gap: clamp(5px, 1vh, 10px);
}

.game-topbar {
  flex: 0 0 auto;
  min-height: 42px;
  padding: 4px 0;
}

.game-heading {
  min-width: 0;
}

.game-heading .eyebrow {
  margin-bottom: 1px;
}

.game-heading h2 {
  margin: 0;
  overflow: hidden;
  color: #ffffff;
  font-size: clamp(0.84rem, 2vw, 1.2rem);
  letter-spacing: -0.03em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-bar {
  display: flex;
  justify-content: center;
  gap: clamp(14px, 3vw, 32px);
  min-width: 130px;
}

.score-item {
  display: grid;
  gap: 1px;
}

.score-item-right {
  text-align: right;
}

.score-label {
  color: var(--muted);
  font-size: 0.58rem;
  font-weight: 800;
  letter-spacing: 0.14em;
}

.score-item strong {
  color: #ffffff;
  font-size: clamp(0.95rem, 2.2vw, 1.35rem);
  line-height: 1;
}

.quiet-button {
  min-height: 34px;
  padding: 6px 10px;
  color: #cbd4ed;
  background: rgba(83, 103, 183, 0.13);
  font-size: clamp(0.62rem, 1.2vw, 0.75rem);
  font-weight: 700;
  white-space: nowrap;
}

.quiet-button span {
  color: #9da9c9;
  font-size: 0.9em;
}

.game-content {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: stretch;
  justify-content: center;
}

.board-column {
  width: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(5px, 1vh, 10px);
}

.board-frame {
  position: relative;
  flex: 0 1 auto;
  height: min(calc(100% - 130px), 720px);
  aspect-ratio: 1 / 2;
  max-width: 88vw;
  overflow: hidden;
  border: clamp(3px, 0.6vw, 5px) solid #263966;
  border-radius: clamp(12px, 2vw, 18px);
  background: var(--board);
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.28);
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--board);
}

.game-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  gap: clamp(3px, 0.8vh, 7px);
  padding: clamp(8px, 2vw, 20px);
  color: #f5f7ff;
  text-align: center;
  background: rgba(7, 13, 34, 0.92);
}

.overlay-kicker {
  margin: 0;
  color: var(--danger);
  font-size: clamp(0.55rem, 1.4vw, 0.72rem);
  font-weight: 800;
  letter-spacing: 0.16em;
}

.game-overlay h3 {
  margin: 0;
  font-size: clamp(0.95rem, 3vw, 1.45rem);
}

.game-over-message {
  margin: 0;
  color: #cbd4ed;
  font-size: clamp(0.58rem, 1.6vw, 0.76rem);
}

.overlay-score-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin: 2px 0;
}

.overlay-score-grid div {
  display: grid;
  gap: 1px;
  padding: 6px 4px;
  border: 1px solid rgba(153, 177, 255, 0.16);
  border-radius: 8px;
  background: rgba(4, 10, 29, 0.3);
}

.overlay-score-grid span {
  color: #aeb8d6;
  font-size: clamp(0.53rem, 1.3vw, 0.66rem);
}

.overlay-score-grid strong {
  color: #ffffff;
  font-size: clamp(0.84rem, 2.6vw, 1.18rem);
  line-height: 1.1;
}

.score-entry-form {
  margin-top: 1px;
  text-align: left;
}

.input-label {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 4px;
  color: #e4e9fb;
  font-size: clamp(0.57rem, 1.4vw, 0.72rem);
  font-weight: 700;
}

.input-label span {
  color: var(--muted);
  font-size: 0.9em;
  font-weight: 400;
  white-space: nowrap;
}

.score-entry-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 5px;
}

#playerName {
  width: 100%;
  min-width: 0;
  min-height: 32px;
  padding: 5px 8px;
  border: 1px solid rgba(185, 197, 255, 0.28);
  border-radius: 7px;
  color: #ffffff;
  background: rgba(4, 10, 29, 0.65);
  font-size: 16px;
}

#playerName::placeholder {
  color: #7281a6;
}

#playerName:focus {
  border-color: #9aa6ff;
  outline: 3px solid rgba(141, 155, 255, 0.18);
}

.score-entry-row .primary-button {
  min-width: 48px;
  min-height: 32px;
  padding: 5px 8px;
  border-radius: 7px;
  font-size: clamp(0.65rem, 1.6vw, 0.78rem);
}

.form-message {
  min-height: 1.15em;
  margin: 3px 0 0;
  color: #ffb2bd;
  font-size: clamp(0.53rem, 1.3vw, 0.66rem);
}

.overlay-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 5px;
  margin-top: 2px;
}

.overlay-actions .primary-button,
.overlay-actions .secondary-button {
  min-height: 30px;
  padding: 4px 5px;
  border-radius: 7px;
  font-size: clamp(0.57rem, 1.4vw, 0.7rem);
}

.status-message {
  width: min(100%, 360px);
  min-height: 1.25em;
  margin: 0;
  overflow: hidden;
  color: #d8e0f7;
  font-size: clamp(0.63rem, 1.4vw, 0.78rem);
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.control-pad {
  width: min(100%, 360px);
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(5px, 1vw, 8px);
}

.control-button {
  min-height: clamp(36px, 6.2vh, 52px);
  padding: 5px 4px;
  background: rgba(83, 103, 183, 0.2);
  font-size: clamp(0.74rem, 1.8vw, 0.92rem);
  font-weight: 800;
}

.control-button:hover {
  border-color: rgba(185, 197, 255, 0.55);
  background: rgba(100, 122, 219, 0.32);
}

.control-button-rotate span {
  color: #aeb8ff;
  font-size: 0.75em;
  font-weight: 700;
}

.control-button-wide {
  grid-column: 1 / -1;
  background: rgba(83, 103, 183, 0.12);
  font-size: clamp(0.68rem, 1.6vw, 0.82rem);
}

.control-button-wide span {
  color: #aeb8d6;
  font-size: 0.86em;
  font-weight: 600;
}

.ranking-screen {
  display: grid;
  place-items: center;
}

.ranking-screen-inner {
  width: min(100%, 720px);
  max-height: 100%;
  display: flex;
  flex-direction: column;
  gap: clamp(9px, 2vh, 18px);
}

.ranking-topbar {
  flex: 0 0 auto;
}

.ranking-topbar h2 {
  margin: 0;
  color: #ffffff;
  font-size: clamp(1.2rem, 4vw, 2rem);
  letter-spacing: -0.05em;
}

.ranking-topbar h2 span {
  color: #aeb8ff;
  font-size: 0.55em;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.ranking-card {
  min-height: 0;
  max-height: calc(100% - 58px);
  padding: clamp(14px, 2.5vw, 24px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--panel-border);
  border-radius: clamp(16px, 2.5vw, 22px);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.ranking-card-heading {
  flex: 0 0 auto;
}

.ranking-card-heading h3 {
  font-size: clamp(0.92rem, 2.2vw, 1.2rem);
}

.ranking-card-heading p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: clamp(0.64rem, 1.4vw, 0.76rem);
}

.ranking-trophy {
  font-size: clamp(1.7rem, 5vw, 2.6rem);
  filter: drop-shadow(0 6px 12px rgba(249, 210, 118, 0.18));
}

.ranking-status {
  flex: 0 0 auto;
  min-height: 1.3em;
  margin: clamp(9px, 1.5vh, 14px) 0 7px;
  color: var(--muted);
  font-size: clamp(0.64rem, 1.4vw, 0.76rem);
}

.ranking-list {
  min-height: 0;
  flex: 1 1 auto;
  display: grid;
  grid-auto-rows: minmax(25px, 1fr);
  gap: 5px;
  margin: 0;
  padding: 0;
  overflow: hidden;
  list-style: none;
}

.ranking-row {
  display: grid;
  grid-template-columns: 2rem minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-height: 25px;
  padding: 4px 8px;
  border: 1px solid rgba(153, 177, 255, 0.1);
  border-radius: 8px;
  background: rgba(4, 10, 29, 0.26);
  font-size: clamp(0.68rem, 1.5vw, 0.8rem);
}

.ranking-row:first-child {
  border-color: rgba(249, 210, 118, 0.36);
  background: rgba(249, 210, 118, 0.08);
}

.ranking-rank {
  color: #aeb8ff;
  font-weight: 800;
  text-align: center;
}

.ranking-row:first-child .ranking-rank {
  color: #f9d276;
}

.ranking-player {
  overflow: hidden;
  color: #e4e9fb;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ranking-score {
  color: #ffffff;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  white-space: nowrap;
}

.ranking-empty {
  display: grid;
  min-height: 50px;
  place-items: center;
  color: var(--muted);
  font-size: clamp(0.68rem, 1.5vw, 0.8rem);
  text-align: center;
}

.ranking-refresh {
  width: 100%;
  flex: 0 0 auto;
  min-height: 36px;
  margin-top: 10px;
  padding: 6px 10px;
  color: #cdd6f4;
  background: transparent;
  font-size: clamp(0.68rem, 1.5vw, 0.78rem);
  font-weight: 700;
}

.ranking-note {
  margin: 0;
  color: #8d9abb;
  font-size: clamp(0.62rem, 1.3vw, 0.72rem);
  text-align: center;
}

.page-footer {
  color: #7382a5;
  font-size: 0.62rem;
  text-align: center;
}

@media (max-width: 600px) {
  .app-shell {
    padding-right: 10px;
    padding-left: 10px;
  }

  .site-header {
    font-size: 0.58rem;
  }

  .site-tag {
    font-size: 0.5rem;
  }

  .title-card {
    padding: 14px;
    border-radius: 18px;
  }

  .title-copy h1 {
    font-size: clamp(1.9rem, 9vw, 3.2rem);
  }

  .title-lead {
    margin-top: 9px;
    font-size: 0.76rem;
  }

  .title-actions {
    margin-top: 12px;
  }

  .title-action {
    min-height: 39px;
    padding: 7px 5px;
    border-radius: 9px;
    font-size: 0.72rem;
  }

  .rules-panel {
    margin-top: 12px;
    padding: 11px;
    border-radius: 14px;
  }

  .rules-grid {
    gap: 5px;
    margin-top: 9px;
  }

  .rule-item {
    display: block;
    padding: 7px;
  }

  .rule-number {
    display: block;
    margin-bottom: 3px;
    font-size: 0.58rem;
  }

  .rule-item h3 {
    font-size: 0.66rem;
  }

  .rule-item p {
    font-size: 0.57rem;
    line-height: 1.35;
  }

  .operation-guides {
    gap: 4px;
    margin-top: 6px;
  }

  .operation-guide {
    padding: 7px 5px;
  }

  .operation-guide h3 {
    font-size: 0.62rem;
  }

  .operation-guide p {
    font-size: 0.56rem;
    line-height: 1.35;
  }

  .danger-note {
    margin-top: 7px;
    padding: 6px 7px;
    font-size: 0.57rem;
  }

  .game-topbar {
    gap: 6px;
  }

  .score-bar {
    min-width: 112px;
    gap: 11px;
  }

  .score-label {
    font-size: 0.5rem;
  }

  .score-item strong {
    font-size: 0.9rem;
  }

  .quiet-button {
    min-height: 31px;
    padding: 5px 6px;
    border-radius: 8px;
    font-size: 0.58rem;
  }

  .quiet-button span {
    display: block;
    font-size: 0.85em;
    line-height: 1;
  }

  .control-button-rotate span {
    display: none;
  }

  .control-button-wide span {
    font-size: 0.75em;
  }

  .ranking-topbar {
    gap: 7px;
  }

  .ranking-topbar h2 {
    font-size: 1.35rem;
  }

  .ranking-card {
    padding: 13px;
  }
}

@media (max-height: 680px) {
  .app-shell {
    gap: 4px;
    padding-top: 6px;
    padding-bottom: 5px;
  }

  .site-header {
    min-height: 20px;
  }

  .game-screen {
    gap: 3px;
  }

  .game-topbar {
    min-height: 36px;
  }

  .board-frame {
    height: min(calc(100% - 112px), 650px);
  }

  .board-column {
    gap: 4px;
  }

  .control-button {
    min-height: 34px;
  }

  .status-message {
    font-size: 0.6rem;
  }

  .page-footer {
    font-size: 0.56rem;
  }
}

@media (max-width: 370px) {
  .site-tag {
    display: none;
  }

  .title-copy h1 {
    font-size: 1.78rem;
  }

  .title-lead {
    font-size: 0.7rem;
  }

  .title-action {
    font-size: 0.66rem;
  }

  .section-heading h2 {
    font-size: 0.92rem;
  }

  .section-badge {
    padding: 3px 5px;
    font-size: 0.5rem;
  }

  .game-heading h2 {
    font-size: 0.76rem;
  }

  .score-bar {
    min-width: 100px;
    gap: 7px;
  }

  .score-item strong {
    font-size: 0.8rem;
  }

  .quiet-button {
    font-size: 0.52rem;
  }
}
