@font-face {
  font-family: "Pixeloid Sans";
  src: url("./PixeloidSans.otf") format("opentype");
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000000;
  color: #f5e6c8;
  font-family: "Pixeloid Sans", monospace;
  position: fixed;
  inset: 0;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

#gameCanvas {
  display: block;
  width: 100vw;
  height: 100vh;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

/* Offscreen native input: opens the OS keyboard for canvas text fields on mobile. */
#mobileTextProxy {
  position: fixed;
  left: -9999px;
  top: 0;
  width: 1px;
  height: 1px;
  margin: 0;
  padding: 0;
  border: 0;
  opacity: 0.01;
  color: transparent;
  caret-color: transparent;
  background: transparent;
  outline: none;
  font-size: 16px;
  z-index: 20;
  -webkit-user-select: text;
  user-select: text;
  touch-action: manipulation;
}

/* —— Spell creator: game-theme panel (tokens from JS) —— */
.spell-create-panel {
  --sc-panel: rgba(22, 12, 32, 0.96);
  --sc-header: #3d2458;
  --sc-border: rgba(212, 168, 75, 0.45);
  --sc-text: #f5e6c8;
  --sc-soft: #c9b08a;
  --sc-accent: #e8b84a;
  --sc-row: #261a30;
  --sc-row-muted: #2a2238;
  --sc-btn: #5c3d22;
  --sc-btn-alt: #4a3558;
  --sc-btn-hover: #7a5230;
  --sc-on: #9a6538;
  --sc-track: #1a1224;

  position: fixed;
  z-index: 15;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--sc-panel);
  border: 1px solid var(--sc-border);
  color: var(--sc-text);
  font-family: "Pixeloid Sans", monospace;
  font-size: 12px;
  -webkit-user-select: none;
  user-select: none;
  touch-action: auto;
  pointer-events: auto;
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.35);
}

.spell-create-panel[hidden] {
  display: none !important;
}

.spell-create-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  padding: 10px 12px;
  border-bottom: 1px solid var(--sc-border);
  background: linear-gradient(180deg, color-mix(in srgb, var(--sc-accent) 18%, transparent), var(--sc-header));
}

.spell-create-title-wrap {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.spell-create-head .spell-create-nav-btn {
  flex: 0 0 auto;
  padding: 7px 12px;
  font-size: 12px;
}

.spell-create-back,
.spell-create-chip,
.spell-create-toggle,
.spell-create-tab,
.spell-create-nav-btn {
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  color: var(--sc-text);
  background: var(--sc-btn);
  border: 1px solid var(--sc-border);
  border-radius: 0;
  padding: 7px 12px;
  appearance: none;
  -webkit-appearance: none;
}

.spell-create-back:hover,
.spell-create-chip:hover,
.spell-create-toggle:hover,
.spell-create-tab:hover,
.spell-create-nav-btn:hover {
  background: var(--sc-btn-hover);
}

.spell-create-title {
  font-size: 14px;
  color: var(--sc-accent);
  letter-spacing: 0.02em;
}

.spell-create-progress {
  color: var(--sc-soft);
  font-size: 11px;
  line-height: 1.2;
}

.spell-create-step {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.spell-create-step[hidden] {
  display: none !important;
}

.spell-create-nav-btn.primary {
  background: var(--sc-btn-alt);
  color: var(--sc-accent);
  border-color: var(--sc-accent);
}

.spell-create-nav-btn.primary:hover {
  background: var(--sc-btn-hover);
  color: var(--sc-text);
}

.spell-create-nav-btn[hidden] {
  display: none !important;
}

.spell-create-form {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 12px 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--sc-accent) var(--sc-track);
}

.spell-create-form::-webkit-scrollbar {
  width: 8px;
}
.spell-create-form::-webkit-scrollbar-track {
  background: var(--sc-track);
}
.spell-create-form::-webkit-scrollbar-thumb {
  background: var(--sc-accent);
}

.spell-create-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.spell-create-field > span,
.spell-create-section-label {
  color: var(--sc-soft);
  font-size: 11px;
}

.spell-create-select {
  box-sizing: border-box;
  width: 100%;
  min-height: 30px;
  padding: 6px 8px;
  background: var(--sc-btn);
  border: 1px solid var(--sc-border);
  border-radius: 0;
  color: var(--sc-text);
  font: inherit;
  font-size: 13px;
}

.spell-create-select:focus {
  outline: 1px solid var(--sc-accent);
}

/* Game-style text fields (clan/chat-like: no native caret/selection) */
.spell-create-tf {
  position: relative;
  box-sizing: border-box;
  width: 100%;
  min-height: 34px;
  padding: 8px 10px;
  background: var(--sc-btn);
  border: 1px solid var(--sc-border);
  border-radius: 0;
  color: var(--sc-text);
  font: inherit;
  font-size: 13px;
  line-height: 1.35;
  cursor: text;
  outline: none;
  -webkit-user-select: none;
  user-select: none;
}

.spell-create-tf.focused {
  background: var(--sc-btn-alt);
  border-color: var(--sc-accent);
}

.spell-create-tf-multi {
  min-height: 72px;
}

.spell-create-tf-body {
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--sc-text);
  min-height: 1.2em;
}

.spell-create-tf-ph {
  position: absolute;
  left: 10px;
  top: 8px;
  right: 10px;
  color: var(--sc-soft);
  opacity: 0.55;
  pointer-events: none;
  white-space: pre-wrap;
  word-break: break-word;
}

.spell-create-tf.has-value .spell-create-tf-ph,
.spell-create-tf.focused.has-value .spell-create-tf-ph {
  display: none;
}

.spell-create-tf-caret {
  display: inline-block;
  width: 2px;
  height: 1.05em;
  margin: 0 0 -0.15em 1px;
  vertical-align: text-bottom;
  background: var(--sc-accent);
  animation: spell-create-caret-blink 1s steps(1, end) infinite;
}

@keyframes spell-create-caret-blink {
  0%,
  49% {
    opacity: 1;
  }
  50%,
  100% {
    opacity: 0;
  }
}

.spell-create-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.spell-create-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 12px;
}

.spell-create-form h3 {
  margin: 8px 0 0;
  font-size: 13px;
  font-weight: normal;
  color: var(--sc-accent);
  border-bottom: 1px solid var(--sc-border);
  padding-bottom: 4px;
}

.spell-create-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.spell-create-toggle {
  background: var(--sc-row);
  opacity: 0.85;
}

.spell-create-toggle.on {
  background: var(--sc-on);
  border-color: var(--sc-accent);
  color: var(--sc-text);
  opacity: 1;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--sc-accent) 35%, transparent);
}

.spell-create-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.spell-create-chip {
  background: var(--sc-row-muted);
  padding: 6px 10px;
  font-size: 11px;
}

.spell-create-chip.on {
  background: var(--sc-btn-alt);
  border-color: var(--sc-accent);
  color: var(--sc-accent);
}

.spell-create-hint {
  color: var(--sc-soft);
  font-size: 10px;
  opacity: 0.8;
}

.spell-create-aoe {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.spell-create-aoe-label {
  color: var(--sc-soft);
  font-size: 11px;
}

.spell-create-aoe-grid {
  display: grid;
  grid-template-columns: repeat(9, 24px);
  gap: 3px;
  width: max-content;
  padding: 6px;
  background: var(--sc-track);
  border: 1px solid var(--sc-border);
}

.spell-create-aoe-cell {
  width: 24px;
  height: 24px;
  box-sizing: border-box;
  border: 1px solid var(--sc-row-muted);
  background: var(--sc-row);
  cursor: pointer;
  padding: 0;
  appearance: none;
}

.spell-create-aoe-cell.on {
  background: var(--sc-accent);
  border-color: var(--sc-text);
}

.spell-create-aoe-cell.anchor {
  outline: 2px solid var(--sc-text);
  outline-offset: -3px;
}

.spell-create-anim-preview {
  display: block;
  width: 100%;
  height: 128px;
  margin-top: 8px;
  box-sizing: border-box;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--sc-row) 70%, transparent), var(--sc-track)),
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent 15px,
      color-mix(in srgb, var(--sc-border) 22%, transparent) 15px,
      color-mix(in srgb, var(--sc-border) 22%, transparent) 16px
    ),
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 15px,
      color-mix(in srgb, var(--sc-border) 22%, transparent) 15px,
      color-mix(in srgb, var(--sc-border) 22%, transparent) 16px
    );
  border: 1px solid var(--sc-border);
  image-rendering: pixelated;
}

.spell-create-footer {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 12px 8px;
  border-top: 1px solid var(--sc-border);
  background: color-mix(in srgb, var(--sc-header) 70%, transparent);
}

.spell-create-preview {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 10px;
  background: color-mix(in srgb, var(--sc-row) 85%, transparent);
  border: 1px solid var(--sc-border);
}

.spell-create-preview-name {
  color: var(--sc-accent);
  font-size: 13px;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.spell-create-preview-name.is-empty {
  color: var(--sc-soft);
  opacity: 0.75;
  font-style: italic;
}

.spell-create-preview-meta {
  color: var(--sc-soft);
  font-size: 11px;
  line-height: 1.3;
}

.spell-create-preview-effect {
  color: var(--sc-text);
  font-size: 12px;
  line-height: 1.35;
  min-height: 1.35em;
}

.spell-create-preview-effect.is-empty {
  color: var(--sc-soft);
  opacity: 0.8;
}

.spell-create-preview-budget {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 2px;
}

.spell-create-preview-bar {
  height: 6px;
  background: var(--sc-track, rgba(0, 0, 0, 0.35));
  border: 1px solid var(--sc-border);
  overflow: hidden;
}

.spell-create-preview-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--sc-accent);
  transition: width 0.18s ease-out, background-color 0.18s ease-out;
}

.spell-create-preview-bar-fill.warn {
  background: #e8b84a;
}

.spell-create-preview-bar-fill.over {
  background: #e85d5d;
}

.spell-create-preview-budget-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
}

.spell-create-cooldown {
  text-align: right;
  color: var(--sc-accent);
  font-size: 12px;
  line-height: 1.2;
  white-space: nowrap;
}

.spell-create-complexity {
  text-align: left;
  color: var(--sc-soft);
  font-size: 12px;
  line-height: 1.2;
}

.spell-create-complexity.over {
  color: #e85d5d;
}

#spellCreateSubmit:disabled,
#spellCreateNext:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.spell-create-status {
  min-height: 0;
  color: var(--sc-soft);
  font-size: 11px;
  text-align: center;
}
.spell-create-status:empty {
  display: none;
}

.spell-create-status.err {
  color: #e85d5d;
}

.spell-create-status.ok {
  color: #8dffb0;
}

.spell-create-subopts {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 8px;
}

.spell-create-field[hidden],
.spell-create-subopts[hidden],
.spell-create-slider[hidden],
.spell-create-aoe[hidden],
.spell-create-chips[hidden],
.spell-create-toggle[hidden],
.spell-create-step[hidden] {
  display: none !important;
}

@keyframes spell-create-reveal {
  from {
    opacity: 0;
    transform: translateY(-5px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.spell-create-reveal {
  animation: spell-create-reveal 0.22s ease-out both;
}

.spell-create-chips.spell-create-reveal .spell-create-chip {
  animation: spell-create-reveal 0.18s ease-out both;
}
.spell-create-chips.spell-create-reveal .spell-create-chip:nth-child(1) { animation-delay: 0.02s; }
.spell-create-chips.spell-create-reveal .spell-create-chip:nth-child(2) { animation-delay: 0.04s; }
.spell-create-chips.spell-create-reveal .spell-create-chip:nth-child(3) { animation-delay: 0.06s; }
.spell-create-chips.spell-create-reveal .spell-create-chip:nth-child(4) { animation-delay: 0.08s; }
.spell-create-chips.spell-create-reveal .spell-create-chip:nth-child(5) { animation-delay: 0.1s; }
.spell-create-chips.spell-create-reveal .spell-create-chip:nth-child(6) { animation-delay: 0.12s; }
.spell-create-chips.spell-create-reveal .spell-create-chip:nth-child(7) { animation-delay: 0.14s; }
.spell-create-chips.spell-create-reveal .spell-create-chip:nth-child(8) { animation-delay: 0.16s; }
.spell-create-chips.spell-create-reveal .spell-create-chip:nth-child(9) { animation-delay: 0.18s; }
.spell-create-chips.spell-create-reveal .spell-create-chip:nth-child(n+10) { animation-delay: 0.2s; }

.spell-create-tab-panel.spell-create-reveal .spell-create-slider {
  animation: spell-create-reveal 0.2s ease-out both;
}
.spell-create-tab-panel.spell-create-reveal .spell-create-slider:nth-child(1) { animation-delay: 0.02s; }
.spell-create-tab-panel.spell-create-reveal .spell-create-slider:nth-child(2) { animation-delay: 0.05s; }
.spell-create-tab-panel.spell-create-reveal .spell-create-slider:nth-child(3) { animation-delay: 0.08s; }
.spell-create-tab-panel.spell-create-reveal .spell-create-slider:nth-child(4) { animation-delay: 0.11s; }
.spell-create-tab-panel.spell-create-reveal .spell-create-slider:nth-child(5) { animation-delay: 0.14s; }
.spell-create-tab-panel.spell-create-reveal .spell-create-slider:nth-child(n+6) { animation-delay: 0.17s; }

@media (prefers-reduced-motion: reduce) {
  .spell-create-reveal,
  .spell-create-chips.spell-create-reveal .spell-create-chip,
  .spell-create-tab-panel.spell-create-reveal .spell-create-slider {
    animation: none;
  }
}

.spell-create-slider {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.spell-create-slider-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  color: var(--sc-soft);
  font-size: 11px;
}

.spell-create-slider-val {
  color: var(--sc-accent);
  font-variant-numeric: tabular-nums;
  min-width: 2.5em;
  text-align: right;
}

.spell-create-form input[type="range"] {
  width: 100%;
  height: 18px;
  margin: 0;
  padding: 0;
  border: none;
  border-bottom: none;
  background: transparent !important;
  -webkit-text-fill-color: unset;
  accent-color: var(--sc-accent);
  cursor: pointer;
}

.spell-create-form input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  background: var(--sc-track);
  border: 1px solid var(--sc-border);
}

.spell-create-form input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  margin-top: -5px;
  background: var(--sc-accent);
  border: 1px solid var(--sc-text);
  cursor: pointer;
}

.spell-create-form input[type="range"]::-moz-range-track {
  height: 6px;
  background: var(--sc-track);
  border: 1px solid var(--sc-border);
}

.spell-create-form input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  background: var(--sc-accent);
  border: 1px solid var(--sc-text);
  border-radius: 0;
  cursor: pointer;
}

.spell-create-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.spell-create-tab {
  background: var(--sc-row);
  opacity: 0.85;
  padding: 6px 10px;
  font-size: 11px;
}

.spell-create-tab.on {
  background: var(--sc-on);
  border-color: var(--sc-accent);
  opacity: 1;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--sc-accent) 35%, transparent);
}

.spell-create-tab-panels {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.spell-create-tab-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 8px 0 2px;
}

.spell-create-tab-panel[hidden],
.spell-create-tab[hidden] {
  display: none !important;
}

@media (max-width: 720px) {
  .spell-create-row,
  .spell-create-grid {
    grid-template-columns: 1fr;
  }
}
