:root {
  --ink: #1f2a24;
  --muted: #5d6b62;
  --line: #d9e2d6;
  --green: #2f7d4f;
  --board: #eef4ea;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: #f7f9f6;
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

.app {
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.stats {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.95rem;
}

.score-label {
  color: var(--muted);
}

.score {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-width: 1.6em;
}

button {
  font: inherit;
  color: var(--ink);
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
}

button:hover:not(:disabled) {
  background: #f0f5ee;
}

button:active:not(:disabled) {
  transform: translateY(1px);
}

button:disabled {
  cursor: default;
  opacity: 0.5;
}

button:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 2px;
}

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
}

.board-wrap {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: var(--board);
  touch-action: none;
}

.board {
  display: block;
  width: 100%;
  height: 100%;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 16px;
  text-align: center;
  background: rgba(247, 249, 246, 0.92);
}

.overlay[hidden] {
  display: none;
}

.overlay h2 {
  margin: 0;
  font-size: 1.05rem;
}

.overlay p {
  margin: 0;
  max-width: 26ch;
  font-size: 0.88rem;
  line-height: 1.45;
  color: var(--muted);
}

.overlay .ranking-status {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--green);
}

.overlay .ranking-status:empty {
  display: none;
}

.overlay button {
  margin-top: 4px;
}

.hint {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 46px);
  grid-template-rows: repeat(3, 40px);
  gap: 6px;
  justify-content: center;
  touch-action: none;
}

.dpad button {
  padding: 0;
  font-size: 0.95rem;
  border-radius: 8px;
}

.dpad .up {
  grid-area: 1 / 2;
}

.dpad .left {
  grid-area: 2 / 1;
}

.dpad .right {
  grid-area: 2 / 3;
}

.dpad .down {
  grid-area: 3 / 2;
}

@media (hover: hover) and (pointer: fine) {
  .dpad {
    display: none;
  }
}

@media (max-height: 470px) {
  .dpad {
    display: none;
  }

  .hint {
    display: none;
  }

  .app {
    gap: 5px;
    padding: 6px 10px 8px;
  }
}
