:root {
  color-scheme: dark;
  --bg: #07080a;
  --panel: #14161b;
  --panel-2: #1c1f26;
  --text: #f2f4f8;
  --muted: #9aa3b2;
  --accent: #3b82f6;
  --accent-2: #60a5fa;
  --danger: #ef4444;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background:
    radial-gradient(1100px 700px at 50% 0%, #172033 0%, transparent 62%),
    linear-gradient(180deg, #0a0c10 0%, #040507 100%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  touch-action: manipulation;
}

body {
  min-height: 100dvh;
}

#stage {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--safe-top) + 6px) 6px calc(var(--safe-bottom) + 6px);
}

#game {
  display: block;
  width: min(calc(100vw - 12px), calc((100dvh - var(--safe-top) - var(--safe-bottom) - 12px) * 0.75));
  height: auto;
  aspect-ratio: 3 / 4;
  background: #000;
  border-radius: 8px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.72), 0 0 0 1px rgba(255, 255, 255, 0.06);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  image-rendering: auto;
}

.overlay {
  position: fixed;
  left: 0;
  right: 0;
  top: var(--vv-top, 0px);
  bottom: auto;
  height: var(--vv-height, 100dvh);
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  background: rgba(0, 0, 0, 0.58);
  backdrop-filter: blur(2.5px);
  -webkit-backdrop-filter: blur(2.5px);
  animation: fade-in 120ms ease-out;
}

.overlay[hidden] {
  display: none;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.sheet {
  width: 100%;
  max-width: 620px;
  max-height: calc(var(--vv-height, 100dvh) - var(--safe-top) - 18px);
  display: flex;
  flex-direction: column;
  gap: 0;
  background: linear-gradient(180deg, #181b22 0%, #111319 100%);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-bottom: none;
  border-radius: 22px 22px 0 0;
  box-shadow: 0 -18px 70px rgba(0, 0, 0, 0.65);
  padding: 0 0 calc(var(--safe-bottom) + 10px);
  animation: sheet-up 180ms cubic-bezier(0.2, 0.85, 0.25, 1);
}

@keyframes sheet-up {
  from { transform: translateY(22px); opacity: 0.6; }
  to { transform: translateY(0); opacity: 1; }
}

.sheet-header {
  flex: 0 0 auto;
  padding: 18px 20px 12px;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 0.2px;
  color: #fff;
  text-align: center;
}

.sheet-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 4px 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.sheet-actions {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px 20px 4px;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  background: rgba(7, 8, 10, 0.32);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field-label,
.choice-group legend {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.2px;
}

.field input {
  width: 100%;
  min-height: 50px;
  padding: 12px 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  background: #0f1116;
  color: var(--text);
  font-size: 17px;
  outline: none;
  caret-color: var(--accent-2);
}

.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.choice-group {
  border: 0;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.choice {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  padding: 9px 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.035);
  font-size: 16px;
}

.choice input {
  width: 22px;
  height: 22px;
  accent-color: var(--accent);
  flex: 0 0 auto;
}

.choice img {
  width: 24px;
  height: 24px;
  object-fit: contain;
  image-rendering: pixelated;
}

.choice-text {
  flex: 1;
}

.string-item {
  padding: 10px 0;
  font-size: 15px;
  line-height: 1.35;
  color: #dfe4ee;
  white-space: pre-wrap;
}

.string-text {
  color: #dfe4ee;
}

.command {
  flex: 1 1 120px;
  min-height: 48px;
  padding: 11px 16px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  background: #22262f;
  color: var(--text);
  font-size: 16px;
  font-weight: 650;
  cursor: pointer;
  touch-action: manipulation;
}

.command:active {
  transform: scale(0.985);
  background: #2b303b;
}

.command.primary {
  border-color: transparent;
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  color: #061225;
  font-weight: 800;
}

.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(54px, 1fr));
  gap: 9px;
  align-content: start;
}

.image-button {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 54px;
  padding: 6px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.04);
  cursor: pointer;
}

.image-button img {
  max-width: 40px;
  max-height: 40px;
  object-fit: contain;
  image-rendering: pixelated;
}

.picker-sheet {
  max-height: 70dvh;
}

.picker-body {
  gap: 8px;
}

.picker-option {
  min-height: 52px;
  padding: 12px 14px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.045);
  color: var(--text);
  font-size: 16px;
  text-align: left;
}

.picker-option:active {
  background: rgba(59, 130, 246, 0.25);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 22px);
  z-index: 60;
  max-width: min(88vw, 520px);
  padding: 11px 16px;
  border-radius: 12px;
  background: rgba(20, 23, 30, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 14px;
  line-height: 1.3;
  transform: translate(-50%, 16px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.55);
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.loading,
.fatal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background:
    radial-gradient(700px 400px at 50% 35%, #182132 0%, transparent 70%),
    #06070a;
  padding: calc(var(--safe-top) + 24px) 24px calc(var(--safe-bottom) + 24px);
}

.loading[hidden],
.fatal[hidden] {
  display: none;
}

.loading-logo {
  font-size: 38px;
  font-weight: 900;
  letter-spacing: -1.2px;
  background: linear-gradient(180deg, #fff, #8ab4ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.spinner {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.14);
  border-top-color: var(--accent-2);
  animation: spin 800ms linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-text {
  font-size: 14px;
  color: var(--muted);
}

.fatal-card {
  width: min(92vw, 520px);
  padding: 22px;
  border-radius: 18px;
  background: #16181e;
  border: 1px solid rgba(239, 68, 68, 0.35);
  box-shadow: 0 20px 70px rgba(0, 0, 0, 0.6);
}

.fatal-card h1 {
  margin: 0 0 10px;
  font-size: 20px;
}

.fatal-card p {
  margin: 0 0 16px;
  color: #c9d0dc;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
}

.fatal-card button {
  min-height: 46px;
  padding: 10px 18px;
  border: 0;
  border-radius: 11px;
  background: var(--danger);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
}

.fatal-hint {
  margin-top: 14px !important;
  font-size: 12px;
  color: var(--muted) !important;
}
