:root {
  color-scheme: light;
  --page-bg: #18212b;
  --surface: #fbfbf8;
  --surface-raised: #ffffff;
  --ink: #1f2933;
  --muted-ink: #52616f;
  --line: #1f2933;
  --hover: #e8eef3;
  --active: #d9e2ea;
  --shadow: 0 12px 30px rgba(24, 33, 43, 0.16);
  --small-shadow: 0 3px 10px rgba(24, 33, 43, 0.12);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, Helvetica, sans-serif;
  background: var(--page-bg);
  color: var(--ink);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--surface);
}

button {
  font: inherit;
  color: inherit;
  background: var(--surface-raised);
  border: 4px solid var(--line);
  border-radius: 14px;
  cursor: pointer;
  box-shadow: var(--small-shadow);
  transition: background-color 120ms ease, transform 120ms ease, box-shadow 120ms ease;
}

button:hover,
button:focus-visible {
  background: var(--hover);
  outline: none;
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(24, 33, 43, 0.14);
}

button:active {
  transform: translateY(1px);
  box-shadow: none;
}

.app {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: grid;
  place-items: center;
  background: var(--surface);
}

.screen {
  background: var(--surface);
}

.stage {
  position: relative;
  width: min(100vw, calc(100vh * 16 / 9));
  width: min(100vw, calc(100dvh * 16 / 9));
  height: min(100vh, calc(100vw * 9 / 16));
  height: min(100dvh, calc(100vw * 9 / 16));
  aspect-ratio: 16 / 9;
  padding: 40px 50px 20px;
  box-shadow: var(--shadow);
}

.hidden {
  display: none !important;
}

.close-button {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 35px;
  height: 35px;
  display: grid;
  place-items: center;
  padding: 0;
  font-size: 25px;
  line-height: 1;
  border-width: 3px;
  box-shadow: none;
  z-index: 5;
}

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

.start-panel {
  display: grid;
  justify-items: center;
  gap: 80px;
}

.start-panel h1 {
  margin: 0;
  font-size: clamp(72px, 9vw, 140px);
  font-weight: 650;
  letter-spacing: 0;
}

.title-start-button {
  width: min(420px, 50vw);
  height: 100px;
  background: var(--ink);
  color: var(--surface);
  font-size: clamp(44px, 5vw, 82px);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-bottom: 12px;
}

.title-start-button:hover,
.title-start-button:focus-visible {
  background: #111923;
  color: var(--surface);
}

.title-options {
  position: absolute;
  right: 34px;
  bottom: 26px;
  display: grid;
  justify-items: end;
  gap: 10px;
}

.music-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-size: clamp(18px, 2.2vw, 34px);
  font-weight: 650;
  letter-spacing: 0;
}

.music-toggle input {
  width: 24px;
  height: 24px;
  accent-color: var(--ink);
}

.reset-save-button {
  width: 118px;
  height: 40px;
  border-width: 3px;
  border-radius: 10px;
  box-shadow: none;
  font-size: 22px;
  font-weight: 650;
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 50px;
  height: 57%;
}

.mode-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  gap: clamp(12px, 2.2vw, 30px);
  padding: clamp(18px, 2.4vw, 34px);
  text-align: left;
  background: var(--surface-raised);
  font-size: clamp(18px, 2vw, 38px);
  box-shadow: var(--small-shadow);
  border-radius: 16px;
}

.mode-card.selected {
  background: var(--hover);
}

.mode-title {
  align-self: center;
  margin-bottom: clamp(20px, 5vw, 80px);
  font-size: clamp(24px, 3.2vw, 65px);
  white-space: nowrap;
}

.mode-select-button {
  position: absolute;
  left: 50%;
  bottom: 190px;
  transform: translateX(-50%);
  width: min(260px, 38vw);
  height: 62px;
  font-size: clamp(28px, 3vw, 52px);
  font-weight: 650;
}

.mode-select-button:hover,
.mode-select-button:focus-visible {
  transform: translateX(-50%) translateY(-1px);
}

.mode-select-button:active {
  transform: translateX(-50%) translateY(1px);
}

.direction-box {
  position: absolute;
  left: 50px;
  right: 50px;
  bottom: 10px;
  height: 164px;
  border: 0;
  border-radius: 18px;
  background: var(--hover);
  padding: 16px 18px;
  font-size: clamp(17px, 2vw, 36px);
  line-height: 1.18;
}

.direction-box p {
  min-height: 1.1em;
  margin: 0 0 4px;
}

.level-panel {
  display: grid;
  justify-items: center;
  gap: clamp(14px, 2.4vh, 34px);
  height: calc(100% - 170px);
}

.level-panel h1 {
  margin: 0;
  font-size: clamp(28px, 4vw, 60px);
  font-weight: 400;
}

.level-picker {
  display: grid;
  grid-template-columns: 90px minmax(120px, 1fr) 90px;
  align-items: center;
  width: min(600px, 65%);
}

.level-picker output {
  display: block;
  text-align: center;
  font-size: clamp(120px, 19vw, 300px);
  line-height: 0.9;
}

.triangle-button {
  position: relative;
  width: 90px;
  height: 90px;
  border: 0;
  background: transparent;
  padding: 0;
  border-radius: 0;
  box-shadow: none;
  transform: none;
}

.triangle-button::before,
.triangle-button::after {
  content: "";
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
}

.triangle-button::before {
  left: 0;
  border-top: 45px solid transparent;
  border-bottom: 45px solid transparent;
  border-right: 76px solid var(--line);
}

.triangle-button::after {
  left: 10px;
  border-top: 35px solid transparent;
  border-bottom: 35px solid transparent;
  border-right: 58px solid var(--surface);
}

.triangle-button.right::before {
  left: auto;
  right: 0;
  border-right: 0;
  border-left: 76px solid var(--line);
}

.triangle-button.right::after {
  left: auto;
  right: 10px;
  border-right: 0;
  border-left: 58px solid var(--surface);
}

.triangle-button:hover,
.triangle-button:focus-visible {
  background: transparent;
  transform: none;
  box-shadow: none;
}

.triangle-button:hover::after,
.triangle-button:focus-visible::after {
  border-right-color: var(--hover);
}

.triangle-button.right:hover::after,
.triangle-button.right:focus-visible::after {
  border-right-color: transparent;
  border-left-color: var(--hover);
}

.start-button,
.ok-button {
  width: min(400px, 48vw);
  height: 92px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-size: clamp(34px, 4.2vw, 80px);
  line-height: 1;
}

.game-screen {
  position: relative;
  width: min(100vw, calc(100vh * 16 / 9));
  width: min(100vw, calc(100dvh * 16 / 9));
  height: min(100vh, calc(100vw * 9 / 16));
  height: min(100dvh, calc(100vw * 9 / 16));
  aspect-ratio: 16 / 9;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--surface);
  touch-action: none;
}

.result-layout {
  height: calc(100% - 110px);
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  align-items: center;
  gap: 40px;
}

.result-layout h1 {
  margin: 0 0 90px;
  text-align: center;
  font-size: clamp(54px, 7vw, 120px);
  font-weight: 400;
}

.result-line {
  margin: 18px 0;
  font-size: clamp(40px, 5vw, 90px);
}

.result-layout > div:first-child {
  padding-left: clamp(28px, 4vw, 64px);
}

.history-box h2 {
  margin: 0 0 20px;
  font-size: clamp(32px, 3.2vw, 60px);
  font-weight: 400;
}

.history-box ol {
  margin: 0;
  padding-left: 0;
  list-style-position: inside;
  font-size: clamp(22px, 2.6vw, 50px);
  line-height: 1.35;
}

.new-score {
  margin-left: 0.4em;
}

.ok-button {
  position: absolute;
  left: 50%;
  bottom: 40px;
  transform: translateX(-50%);
}

.ok-button:hover,
.ok-button:focus-visible {
  transform: translateX(-50%) translateY(-1px);
}

.ok-button:active {
  transform: translateX(-50%) translateY(1px);
}

.portrait-warning {
  display: none;
}

.reset-dialog {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(31, 41, 51, 0.18);
}

.reset-dialog-panel {
  width: min(520px, 86vw);
  display: grid;
  gap: 28px;
  justify-items: center;
  padding: 34px;
  background: var(--surface);
  border: 4px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.reset-dialog-panel p {
  margin: 0;
  font-size: clamp(24px, 3vw, 42px);
  text-align: center;
}

.reset-dialog-actions {
  display: flex;
  gap: 22px;
}

.reset-dialog-actions button {
  width: 130px;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-size: 30px;
  line-height: 1;
}

@media (max-width: 950px) and (orientation: landscape) {
  .stage,
  .game-screen {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    aspect-ratio: auto;
    box-shadow: none;
  }

  .stage {
    padding: 18px;
  }

  .mode-grid {
    gap: 12px;
    height: 54%;
    padding-right: 34px;
  }

  .mode-card {
    border-width: 3px;
    padding: 12px;
    font-size: 16px;
    box-shadow: none;
    min-width: 0;
  }

  .mode-title {
    margin-bottom: 16px;
    font-size: 22px;
    white-space: normal;
  }

  .direction-box {
    left: 18px;
    right: 18px;
    bottom: 12px;
    height: 86px;
    font-size: 18px;
    padding: 10px 12px;
    border-radius: 12px;
  }

  .mode-select-button {
    bottom: 112px;
    width: 170px;
    height: 42px;
    border-width: 3px;
    border-radius: 12px;
    font-size: 24px;
    box-shadow: none;
  }

  .close-button {
    border-width: 3px;
    width: 30px;
    height: 30px;
    font-size: 20px;
  }

  .level-panel {
    height: calc(100% - 100px);
  }

  .level-panel h1 {
    font-size: 28px;
  }

  .level-picker {
    width: 48%;
    grid-template-columns: 52px 1fr 52px;
  }

  .level-picker output {
    font-size: 104px;
  }

  .triangle-button {
    width: 48px;
    height: 48px;
  }

  .triangle-button::before {
    border-top-width: 24px;
    border-bottom-width: 24px;
    border-right-width: 41px;
  }

  .triangle-button::after {
    left: 6px;
    border-top-width: 18px;
    border-bottom-width: 18px;
    border-right-width: 30px;
  }

  .triangle-button.right::before {
    border-left-width: 41px;
  }

  .triangle-button.right::after {
    right: 6px;
    border-left-width: 30px;
  }

  .start-button,
  .ok-button {
    height: 54px;
    border-width: 3px;
    font-size: 34px;
    box-shadow: none;
  }

  .result-layout {
    height: calc(100% - 70px);
    gap: 20px;
  }

  .result-layout h1 {
    margin-bottom: 24px;
    font-size: 48px;
  }

  .result-line {
    font-size: 34px;
  }

  .result-layout > div:first-child {
    padding-left: 86px;
  }

  .history-box h2 {
    font-size: 30px;
  }

  .history-box ol {
    font-size: 22px;
  }

  .ok-button {
    bottom: 14px;
  }
}

@media (max-width: 950px) and (orientation: landscape) and (max-height: 280px) {
  button {
    border-width: 3px;
    border-radius: 10px;
  }

  .stage {
    padding: 10px;
  }

  .start-panel {
    gap: 28px;
  }

  .start-panel h1 {
    font-size: clamp(40px, 10vw, 72px);
  }

  .title-start-button {
    width: 230px;
    height: 58px;
    padding-bottom: 7px;
    font-size: 34px;
  }

  .title-options {
    right: 16px;
    bottom: 12px;
    gap: 5px;
  }

  .music-toggle {
    gap: 6px;
    font-size: 16px;
  }

  .music-toggle input {
    width: 16px;
    height: 16px;
  }

  .reset-save-button {
    width: 74px;
    height: 24px;
    border-width: 2px;
    border-radius: 7px;
    font-size: 13px;
  }

  .reset-dialog-panel {
    width: min(360px, 78vw);
    gap: 14px;
    padding: 18px;
    border-width: 3px;
    border-radius: 12px;
  }

  .reset-dialog-panel p {
    font-size: 20px;
  }

  .reset-dialog-actions {
    gap: 14px;
  }

  .reset-dialog-actions button {
    width: 86px;
    height: 34px;
    border-width: 3px;
    font-size: 18px;
  }

  .mode-grid {
    gap: 8px;
    height: 50%;
    padding-right: 30px;
  }

  .mode-card {
    padding: 8px;
    font-size: 12px;
  }

  .mode-title {
    margin-bottom: 8px;
    font-size: 16px;
  }

  .direction-box {
    left: 10px;
    right: 10px;
    bottom: 8px;
    height: 58px;
    padding: 6px 8px;
    border-radius: 10px;
    font-size: 12px;
    line-height: 1.12;
  }

  .direction-box p {
    margin-bottom: 1px;
  }

  .mode-select-button {
    bottom: 72px;
    width: 132px;
    height: 30px;
    font-size: 17px;
  }

  .close-button {
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    font-size: 16px;
  }

  .level-panel {
    height: calc(100% - 66px);
    gap: 4px;
  }

  .level-panel h1 {
    font-size: 18px;
  }

  .level-picker {
    width: 43%;
    grid-template-columns: 34px 1fr 34px;
  }

  .level-picker output {
    font-size: 64px;
  }

  .triangle-button {
    width: 34px;
    height: 34px;
  }

  .triangle-button::before {
    border-top-width: 17px;
    border-bottom-width: 17px;
    border-right-width: 29px;
  }

  .triangle-button::after {
    left: 5px;
    border-top-width: 12px;
    border-bottom-width: 12px;
    border-right-width: 20px;
  }

  .triangle-button.right::before {
    border-left-width: 29px;
  }

  .triangle-button.right::after {
    right: 5px;
    border-left-width: 20px;
  }

  .start-button,
  .ok-button {
    width: 190px;
    height: 38px;
    font-size: 24px;
  }

  .result-layout {
    height: calc(100% - 44px);
    gap: 10px;
  }

  .result-layout h1 {
    margin-bottom: 8px;
    font-size: 34px;
  }

  .result-line {
    margin: 6px 0;
    font-size: 22px;
  }

  .result-layout > div:first-child {
    padding-left: 66px;
  }

  .history-box h2 {
    margin-bottom: 6px;
    font-size: 20px;
  }

  .history-box ol {
    font-size: 15px;
    line-height: 1.2;
  }

  .ok-button {
    bottom: 8px;
  }
}

@media (max-width: 800px) and (orientation: portrait) {
  .app {
    display: none;
  }

  .portrait-warning {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    display: grid;
    place-items: center;
    padding: 24px;
    background: var(--surface);
    color: var(--ink);
    text-align: center;
  }

  .portrait-warning h1 {
    margin: 0 0 20px;
    font-size: 48px;
    font-weight: 400;
  }

  .portrait-warning p {
    margin: 0;
    font-size: 24px;
    line-height: 1.5;
  }
}
