:root {
  color-scheme: light;
  --ui-scale: 0.75;
  --ink: #1d2433;
  --muted: #687184;
  --line: #d9dee8;
  --paper: #ecf5fa;
  --panel: #ffffff;
  --accent: #1f7a5f;
  --danger: #b43b48;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100svh;
  font-family: "Segoe UI", "Hiragino Sans", "Yu Gothic UI", Meiryo, sans-serif;
  color: var(--ink);
  background: #dde6eb;
  overflow-x: hidden;
  overflow-y: hidden;
}

button {
  font: inherit;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  cursor: wait;
  opacity: 0.62;
}

.app {
  width: min(1400px, 100%);
  min-height: 100svh;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(calc(480px * var(--ui-scale)), calc(645px * var(--ui-scale))) minmax(calc(260px * var(--ui-scale)), calc(360px * var(--ui-scale)));
  gap: calc(24px * var(--ui-scale));
  align-items: center;
  justify-content: center;
  padding: calc(24px * var(--ui-scale));
}

.play-area {
  position: relative;
  display: grid;
  gap: 14px;
  justify-items: center;
}

#game {
  width: min(88vw, calc(572px * var(--ui-scale)));
  height: auto;
  aspect-ratio: 6 / 11;
  display: block;
  border: 1px solid #7c8798;
  background: var(--paper);
  box-shadow: 0 10px 22px rgba(23, 32, 46, 0.16);
}

.fixed-left-ad {
  position: fixed;
  width: 160px;
  height: 600px;
  z-index: 1;
}

.fixed-left-ad[hidden] {
  display: none;
}

#restart {
  min-height: 46px;
  border-radius: 8px;
  font-weight: 700;
  box-shadow: 0 2px 0 rgba(29, 36, 51, 0.12);
}

.screen-overlay,
.gameover-actions {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(70%, 300px);
  display: grid;
  gap: 22px;
  transform: translate(-50%, -50%);
  z-index: 2;
}

.gameover-actions {
  top: calc(50% + 83px);
}

.screen-overlay button,
.gameover-actions button,
.modal button {
  min-height: 62px;
  border-radius: 8px;
  font-size: 20px;
  font-weight: 800;
  box-shadow: 0 3px 0 rgba(29, 36, 51, 0.16);
}

#start-button {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.ranking-button {
  background: #fff8cf;
  border-color: #96884a;
}

.start-help {
  margin: -6px 0 0;
  color: var(--ink);
  font-size: 18px;
  font-weight: 700;
  line-height: 1.55;
  text-align: center;
}

#howto-button,
#game-list-button {
  justify-self: center;
  width: 132px;
  min-height: 42px;
  padding: 0 22px;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 800;
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(29, 36, 51, 0.48);
  z-index: 10;
}

.screen-overlay[hidden],
.modal[hidden],
.gameover-actions[hidden] {
  display: none;
}

.modal-panel {
  width: min(421px, calc(100vw - 32px));
  padding: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 18px 36px rgba(23, 32, 46, 0.22);
}

.modal-panel h2 {
  margin: 0 0 12px;
  font-size: 22px;
}

.modal-panel p {
  margin: 0 0 6px;
  color: var(--muted);
  line-height: 1.5;
}

.modal-panel #name-score {
  margin-bottom: 12px;
}

.modal-panel input {
  width: 100%;
  min-height: 46px;
  margin: 0 0 4px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
}

.modal-panel .input-help {
  margin: 0 0 12px;
  font-size: 13px;
}

.howto-panel {
  width: min(520px, calc(100vw - 32px));
}

.howto-panel p {
  color: var(--ink);
  font-size: 16px;
}

.howto-panel ul {
  margin: 4px 0 12px;
  padding-left: 1.3em;
  color: var(--ink);
  font-size: 16px;
  line-height: 1.55;
}

.howto-panel button {
  width: 100%;
  margin-top: 8px;
}

.ranking-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  width: 66.666%;
  margin-bottom: 12px;
  margin-left: auto;
  margin-right: auto;
}

.ranking-tabs button {
  min-height: 38px;
  font-size: 14px;
}

.ranking-tabs button.active {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.ranking-table {
  max-height: min(70vh, 760px);
  height: min(70vh, 570px);
  width: calc(100% + 30px);
  margin: 0 -15px 14px;
  line-height: 1.9;
  font-size: 21px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf0;
}

.ranking-table .rank-row,
.rank-empty {
  padding: 3px 8px;
  border-bottom: 1px solid var(--line);
}

.ranking-table .rank-row:last-child,
.rank-empty:last-child {
  border-bottom: 0;
}

.rank-row {
  display: grid;
  grid-template-columns: 58px 128px calc(7.4em + 22px);
  align-items: baseline;
  width: 100%;
}

.rank-place {
  font-weight: 700;
  padding-right: 8px;
  border-right: 1px solid var(--line);
  white-space: nowrap;
}

.rank-score {
  padding: 0 10px 0 8px;
  border-right: 1px solid var(--line);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.rank-name {
  padding-left: 10px;
  color: var(--muted);
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#ranking-list .rank-row {
  display: grid !important;
  grid-template-columns: 58px 128px calc(7.4em + 22px) !important;
}

.side {
  display: grid;
  gap: 14px;
  align-content: start;
  align-self: start;
  margin-left: calc(24px * var(--ui-scale));
  padding-top: 130px;
  transform: translateY(var(--side-y-adjust, 0px));
}

.brand h1 {
  margin: 0 0 8px;
  font-size: clamp(30px, 4vw, 46px);
  line-height: 0.95;
  letter-spacing: 0;
}

.brand p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.panel,
.stats {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 24px rgba(23, 32, 46, 0.08);
}

.panel {
  padding: 14px;
}

.panel h2 {
  margin: 0 0 10px;
  font-size: 18px;
}

.next-panel {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 14px;
  align-items: center;
}

#next {
  width: calc(192px * var(--ui-scale));
  height: calc(156px * var(--ui-scale));
}

.stats {
  display: grid;
  grid-template-columns: 1fr;
  overflow: hidden;
}

.stats div {
  min-width: 0;
  padding: 14px 12px;
  position: relative;
}

.stats span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.stats strong {
  display: block;
  margin-top: 3px;
  font-size: 40px;
  white-space: nowrap;
}

.stats em {
  position: absolute;
  right: 12px;
  bottom: 14px;
  color: var(--muted);
  font-size: 15px;
  font-style: normal;
  font-weight: 700;
}

.rules ul {
  margin: 0;
  padding-left: 0;
  columns: 2;
  column-gap: 28px;
  color: var(--muted);
  line-height: 1.75;
  font-size: 16px;
  list-style: none;
}

.rules p {
  margin: 10px 0 0;
  color: var(--ink);
  font-size: 16px;
  line-height: 1.5;
}

.controls {
  display: grid;
}

#restart {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

@media (max-width: 820px) {
  .app {
    min-height: auto;
    grid-template-columns: 1fr;
    padding: 14px;
    gap: 16px;
  }

  .side {
    order: -1;
    align-content: start;
    margin-left: 0;
  }

  .brand h1 {
    font-size: 36px;
  }

  .brand p,
  .rules {
    display: none;
  }

  .stats strong {
    font-size: 17px;
  }
}
