:root {
  --bg: #eef1f4;
  --panel: #ffffff;
  --line: #d9e0e6;
  --text: #1f2933;
  --muted: #6b7785;
  --accent: #2f9e6f;
  --accent-strong: #237a56;
  --danger: #c0392b;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Malgun Gothic", "Apple SD Gothic Neo", system-ui, -apple-system, sans-serif;
  display: flex;
  justify-content: center;
}

.game {
  width: 100%;
  max-width: 520px;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
}

.hud {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 2px;
}

.hud-item {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.hud-label {
  font-size: 0.8rem;
  color: var(--muted);
}

.hud-value {
  font-size: 1.15rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.goal {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 14px;
  padding: 8px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.goal-target {
  display: flex;
  align-items: center;
  gap: 8px;
}

.goal-label {
  font-size: 0.78rem;
  color: var(--muted);
}

.goal-name {
  font-size: 1rem;
  font-weight: 700;
}

.swatch {
  display: inline-block;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 2px solid rgba(31, 41, 51, 0.18);
  background: #ffffff;
}

.slots {
  display: flex;
  align-items: center;
  gap: 6px;
}

.slot {
  min-width: 48px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  text-align: center;
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.2;
}

.slot.empty {
  background: #f2f5f7;
  color: var(--muted);
  border-style: dashed;
}

.slot-op {
  color: var(--muted);
  font-weight: 700;
}

.feedback {
  flex: 0 0 auto;
  margin: 0;
  min-height: 1.2em;
  text-align: center;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--accent-strong);
}

.feedback.bad {
  color: var(--danger);
}

.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  touch-action: none;
}

#board {
  display: block;
  border-radius: 8px;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 16px;
  text-align: center;
  background: rgba(255, 255, 255, 0.9);
}

.overlay[hidden] {
  display: none;
}

.overlay-text {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.ranking-status {
  margin: 0;
  max-width: 320px;
  font-size: 0.82rem;
  line-height: 1.4;
  color: var(--muted);
  word-break: break-word;
}

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

.btn {
  padding: 10px 22px;
  border: 1px solid var(--accent-strong);
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.btn:hover {
  background: var(--accent-strong);
}

.btn:active {
  transform: translateY(1px);
}

.btn:focus-visible {
  outline: 3px solid rgba(47, 158, 111, 0.35);
  outline-offset: 2px;
}

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

.pad {
  flex: 0 0 auto;
  width: 100%;
  max-width: 260px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-areas:
    ". up ."
    "left down right";
  gap: 8px;
}

.pad-btn {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
  touch-action: manipulation;
}

.pad-btn:active {
  background: #e8eef2;
}

.pad-btn[data-dir="up"] {
  grid-area: up;
}

.pad-btn[data-dir="left"] {
  grid-area: left;
}

.pad-btn[data-dir="down"] {
  grid-area: down;
}

.pad-btn[data-dir="right"] {
  grid-area: right;
}

@media (min-width: 560px) and (pointer: fine) {
  .pad {
    display: none;
  }
}

@media (max-height: 520px) {
  .hint {
    display: none;
  }

  .goal {
    padding: 6px 10px;
  }

  .swatch {
    width: 22px;
    height: 22px;
  }

  .slot {
    min-width: 40px;
    padding: 4px 8px;
  }
}

@media (max-height: 420px) {
  .pad {
    max-width: 190px;
  }

  .pad-btn {
    min-height: 38px;
  }
}
