:root {
  color-scheme: light;
  --ui-bg: rgba(255, 248, 225, 0.9);
  --ui-text: #4a2b16;
  --ui-accent: #e85f2e;
  --ui-accent-2: #ffd36a;
  --ui-border: rgba(97, 54, 25, 0.2);
  --shadow: 0 22px 48px rgba(88, 51, 20, 0.34);
  font-family: "Hiragino Maru Gothic ProN", "Yu Gothic", "Meiryo", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  background: #f8e7bd;
  color: var(--ui-text);
  user-select: none;
  -webkit-user-select: none;
}

body.dark-ui {
  color-scheme: dark;
  --ui-bg: rgba(17, 14, 34, 0.9);
  --ui-text: #f7edff;
  --ui-accent: #9f6bff;
  --ui-accent-2: #61e4ff;
  --ui-border: rgba(201, 181, 255, 0.26);
  --shadow: 0 18px 44px rgba(0, 0, 0, 0.42);
  background: #111327;
}

button {
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
}

#app {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100dvh;
  min-height: 100%;
  overflow: hidden;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#gameCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  padding: calc(18px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) calc(18px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
  pointer-events: none;
}

#titleScreen {
  align-items: end;
  align-content: end;
  justify-items: center;
}

#titleScreen .panel {
  align-self: end;
}

.screen--active {
  display: grid;
  pointer-events: auto;
}

.panel {
  width: min(92vw, 420px);
  max-height: calc(100dvh - 36px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  padding: clamp(20px, 5vw, 30px);
  border: 2px solid var(--ui-border);
  border-radius: 8px;
  background: var(--ui-bg);
  box-shadow: var(--shadow);
  text-align: center;
  backdrop-filter: blur(10px);
  outline: 1px solid rgba(255, 255, 255, 0.38);
}

.panel--compact {
  width: min(88vw, 360px);
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  margin: 0 0 10px;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--ui-accent-2);
  color: #3f2514;
  font-size: 0.82rem;
  font-weight: 900;
}

body.dark-ui .badge {
  color: #111327;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 12px;
  font-size: clamp(2.15rem, 10vw, 3.25rem);
  line-height: 1.06;
  letter-spacing: 0;
  color: #3b1e0b;
  text-shadow:
    0 2px 0 rgba(255, 255, 255, 0.9),
    0 5px 14px rgba(80, 42, 16, 0.28);
}

h2 {
  margin-bottom: 18px;
  font-size: clamp(1.8rem, 8vw, 2.5rem);
}

body.dark-ui h1 {
  color: #0b0611;
  text-shadow:
    0 0 8px rgba(190, 95, 255, 0.86),
    0 2px 0 rgba(255, 255, 255, 0.34),
    0 8px 20px rgba(0, 0, 0, 0.72);
}

.lead {
  margin-bottom: 14px;
  font-size: 1rem;
  font-weight: 800;
}

.hint {
  margin: 12px 0 0;
  font-size: 0.9rem;
  font-weight: 700;
  opacity: 0.78;
}

.mode-switch {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
}

.mode-button {
  width: 100%;
  border: 2px solid var(--ui-border);
  background: rgba(255, 255, 255, 0.66);
  color: var(--ui-text);
}

body.dark-ui .mode-button {
  background: rgba(255, 255, 255, 0.08);
}

.mode-button.selected {
  border-color: var(--ui-accent);
  background: var(--ui-accent);
  color: #fff;
  box-shadow: 0 0 0 4px rgba(232, 95, 46, 0.2);
}

body.dark-ui .mode-button.selected {
  box-shadow: 0 0 0 4px rgba(159, 107, 255, 0.24);
}

.primary-button,
.secondary-button {
  width: 100%;
}

.primary-button {
  background: linear-gradient(180deg, var(--ui-accent-2), var(--ui-accent));
  color: #fff;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.24);
}

.secondary-button {
  margin-top: 10px;
  border: 2px solid var(--ui-border);
  background: transparent;
  color: var(--ui-text);
}

.result-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 0 0 18px;
}

.result-list div {
  padding: 12px 8px;
  border: 2px solid var(--ui-border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.42);
}

body.dark-ui .result-list div {
  background: rgba(255, 255, 255, 0.08);
}

dt {
  margin-bottom: 4px;
  font-size: 0.78rem;
  font-weight: 800;
  opacity: 0.76;
}

dd {
  margin: 0;
  font-size: 1.55rem;
  font-weight: 900;
}

@media (orientation: landscape) {
  .panel {
    width: min(78vw, 520px);
    padding: 18px;
  }

  h1 {
    font-size: clamp(1.9rem, 6vw, 2.8rem);
  }

  .mode-switch {
    grid-template-columns: 1fr 1fr;
  }
}
