:root {
  --bg: #f7f5f2;
  --ink: #535353;
  --muted: #8a8a8a;
  --line: #d6d2cc;
  --accent: #c9775b;
  --panel: #ffffff;
  --soft: #efeae4;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  min-height: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  color: var(--ink);
  background: #f7f5f2;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 48px 0 56px;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  padding-bottom: calc(56px + env(safe-area-inset-bottom));
}

.page {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 36px;
}

.header,
.footer {
  text-align: center;
  padding: 0 16px;
}

.header {
  padding-top: 24px;
  padding-bottom: 8px;
}

.code {
  font-family: "Press Start 2P", monospace;
  font-size: clamp(22px, 4vw, 32px);
  color: var(--accent);
  letter-spacing: 0.04em;
  line-height: 1;
  margin-bottom: 18px;
}

.title {
  font-family: "Press Start 2P", monospace;
  font-size: clamp(10px, 1.6vw, 12px);
  font-weight: 400;
  color: var(--ink);
  margin-bottom: 16px;
}

.hint {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.6;
}

.mobile-hint-top {
  display: none;
}

kbd {
  font-family: inherit;
  font-size: 11px;
  border: 1px solid var(--line);
  background: transparent;
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 2px 6px;
  color: var(--ink);
}

.stage {
  width: 100%;
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0;
  box-shadow: none;
}

#game {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 800 / 200;
  min-height: 180px;
  background: transparent;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.mobile-hint {
  display: none;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  margin-top: 8px;
  padding: 0 16px;
}

.reset-btn,
.opt {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.customize {
  width: 100%;
  padding: 0 16px;
}

.customize-inner {
  width: min(920px, 100%);
  margin: 0 auto;
  background: linear-gradient(180deg, #fffdfb 0%, #f3eee8 100%);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 22px 20px 18px;
}

.customize-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.customize-kicker {
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 6px;
}

.customize-title {
  font-family: "Press Start 2P", monospace;
  font-size: 11px;
  font-weight: 400;
  color: var(--ink);
}

.customize-note {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 18px;
  line-height: 1.5;
}

.reset-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  font: inherit;
  font-size: 11px;
  padding: 8px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.reset-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: #fff8f5;
}

.customize-rows {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.cat-row {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 12px;
  align-items: start;
  padding: 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid rgba(214, 210, 204, 0.7);
}

.cat-label {
  font-size: 11px;
  color: var(--ink);
  padding-top: 14px;
  letter-spacing: 0.02em;
}

.cat-label span {
  display: block;
  color: var(--muted);
  font-size: 10px;
  margin-top: 4px;
}

.cat-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.opt {
  width: 52px;
  height: 52px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  cursor: pointer;
  display: block;
  padding: 0;
  overflow: hidden;
  transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
  position: relative;
}

.opt:hover {
  border-color: #c4bbb2;
  transform: translateY(-1px);
}

.opt.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(201, 119, 91, 0.18);
}

.opt-thumb {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 10px;
  box-sizing: border-box;
}

.opt img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  object-position: center;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  pointer-events: none;
  transform: scale(0.92);
}

.opt-none {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.footer {
  text-align: center;
  padding: 8px 16px 8px;
}

.home {
  color: var(--muted);
  text-decoration: none;
  font-size: 11px;
  border-bottom: 1px solid transparent;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.home:hover {
  color: var(--accent);
  border-color: var(--accent);
}

@media (max-width: 640px) {
  body {
    padding-top: 28px;
    padding-bottom: calc(32px + env(safe-area-inset-bottom));
  }

  .page {
    gap: 24px;
  }

  .header {
    padding-top: 8px;
  }

  .code {
    margin-bottom: 12px;
  }

  .title {
    margin-bottom: 10px;
  }

  .desktop-hint {
    display: none;
  }

  .mobile-hint-top,
  .mobile-hint {
    display: block;
  }

  #game {
    min-height: 50vh;
    height: 50vh;
    aspect-ratio: auto;
    width: 100%;
  }

  .customize {
    padding: 0 12px;
  }

  .customize-inner {
    padding: 16px 12px 14px;
    border-radius: 14px;
  }

  .customize-top {
    align-items: center;
    gap: 10px;
  }

  .customize-title {
    font-size: 10px;
  }

  .customize-note {
    font-size: 10px;
    margin-bottom: 14px;
  }

  .reset-btn {
    flex-shrink: 0;
    padding: 10px 12px;
    min-height: 40px;
  }

  .cat-row {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 10px;
  }

  .cat-label {
    padding-top: 0;
  }

  .cat-options {
    gap: 8px;
  }

  .opt {
    width: 46px;
    height: 46px;
    min-width: 46px;
    min-height: 46px;
  }

  .opt-thumb {
    padding: 8px;
  }

  .opt:hover {
    transform: none;
  }

  .opt:active,
  .opt.is-active {
    border-color: var(--accent);
  }
}

@media (hover: none) and (pointer: coarse) {
  .desktop-hint {
    display: none;
  }

  .mobile-hint-top,
  .mobile-hint {
    display: block;
  }

  .opt:hover {
    transform: none;
    border-color: var(--line);
  }

  .opt.is-active {
    border-color: var(--accent);
  }
}
