@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600;700&family=Noto+Sans+Thai:wght@400;500;600;700&display=swap");

:root {
  --void: #050811;
  --steel-panel: #0B1120;
  --system-cyan: #00E5FF;
  --mana-blue: #38BDF8;
  --imperial-gold: #F5B942;
  --imperial-gold-bright: #FBBF24;
  --arcane-purple: #C084FC;
  --abyss-crimson: #F43F5E;
  --recovery-emerald: #10B981;
  --slate-rarity: #94A3B8;
  --ink: #E5F1F8;
  --muted: #A4B7CA;
  --line: rgba(56, 189, 248, 0.32);
  --surface: linear-gradient(165deg, rgba(11,18,34,0.92), rgba(5,8,17,0.96));
  --scanlines: repeating-linear-gradient(0deg, transparent 0 3px, rgba(143,219,255,0.035) 3px 4px);
  --cut-small: polygon(8px 0, 100% 0, 100% calc(100% - 8px), calc(100% - 8px) 100%, 0 100%, 0 8px);
  --cut-medium: polygon(14px 0, 100% 0, 100% calc(100% - 14px), calc(100% - 14px) 100%, 0 100%, 0 14px);
  --cut-cta: polygon(10px 0, 100% 0, calc(100% - 10px) 100%, 0 100%);
  --body-font: "Noto Sans Thai", Inter, sans-serif;
  --mono: "JetBrains Mono", "Noto Sans Thai", monospace;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
.chamfer-sm { clip-path: var(--cut-small); }
.chamfer-md { clip-path: var(--cut-medium); }
.chamfer-btn { clip-path: var(--cut-cta); }
.system-sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.system-ui {
  color: var(--ink);
  background-color: var(--void);
  font-family: var(--body-font);
  font-size: 13px;
  line-height: 1.5;
}
.system-mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.system-grid {
  background-color: var(--void);
  background-image:
    radial-gradient(ellipse at 50% 45%, rgba(0,229,255,.07), transparent 65%),
    linear-gradient(rgba(56,189,248,.065) 1px, transparent 1px),
    linear-gradient(90deg, rgba(56,189,248,.065) 1px, transparent 1px);
  background-size: auto, 32px 32px, 32px 32px;
}
.system-icon {
  display: inline-block;
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  vertical-align: middle;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Both paint layers share the chamfer. The inset reveals the 1px frame. */
.system-frame {
  --frame-line: var(--line);
  --frame-cut: var(--cut-small);
  --frame-fill: var(--scanlines), var(--surface);
  position: relative;
  isolation: isolate;
  clip-path: var(--frame-cut);
  backdrop-filter: blur(10px);
}
.system-frame::before, .system-frame::after {
  content: "";
  position: absolute;
  pointer-events: none;
  z-index: -1;
  clip-path: var(--frame-cut);
}
.system-frame::before { inset: 0; background: var(--frame-line); }
.system-frame::after { inset: 1px; background: var(--frame-fill); }
.system-frame--medium { --frame-cut: var(--cut-medium); }

.system-button {
  --accent: var(--system-cyan);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-width: 0;
  min-height: 36px;
  padding: 6px 12px;
  border: 0;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font: 600 12px/1.3 var(--body-font);
  text-align: center;
  text-decoration: none;
  transition: color 150ms ease, filter 150ms ease;
  -webkit-tap-highlight-color: transparent;
}
.system-button:hover, .system-button[aria-pressed="true"] {
  --frame-line: var(--accent);
  --frame-fill: var(--scanlines), linear-gradient(145deg, #12354B, var(--steel-panel));
  color: var(--accent);
}
.system-button:active { filter: brightness(.83); }
.system-button:focus-visible, .system-swatch:focus-visible {
  outline: 0;
  --frame-line: var(--system-cyan);
  box-shadow: inset 0 0 0 3px var(--ink);
}
.system-button:disabled { opacity: .45; cursor: default; }
.system-button.system-mono { font-family: var(--mono); }
.system-button--primary {
  --frame-cut: var(--cut-cta);
  --frame-line: var(--system-cyan);
  --frame-fill: var(--scanlines), linear-gradient(105deg, #00E5FF, #51E7F8 56%, #38BDF8);
  color: var(--void);
  padding-inline: 18px;
  font-weight: 700;
}
.system-button--primary:hover {
  --frame-fill: var(--scanlines), linear-gradient(105deg, #63F1FF, #38BDF8);
  color: var(--void);
}
.system-button--primary:focus-visible { box-shadow: inset 0 0 0 3px var(--void); }
.system-button--gold, .system-button--danger {
  --frame-line: var(--accent);
  --frame-fill: var(--scanlines), linear-gradient(145deg, color-mix(in srgb, var(--accent) 20%, var(--steel-panel)), var(--void));
  color: var(--accent);
}
.system-button--gold { --accent: var(--imperial-gold); }
.system-button--danger { --accent: var(--abyss-crimson); color: #FF9AAE; }
.system-button--gold:hover, .system-button--danger:hover {
  --frame-fill: var(--scanlines), linear-gradient(145deg, color-mix(in srgb, var(--accent) 35%, var(--steel-panel)), var(--void));
}
.system-button--ghost { color: var(--muted); }

.system-window {
  --accent: var(--system-cyan);
  --frame-line: color-mix(in srgb, var(--accent) 64%, var(--steel-panel));
  padding: 18px;
}
.system-window--danger { --accent: var(--abyss-crimson); }
.system-window::after {
  background:
    linear-gradient(var(--accent),var(--accent)) 7px 7px / 14px 1px no-repeat,
    linear-gradient(var(--accent),var(--accent)) 7px 7px / 1px 14px no-repeat,
    linear-gradient(var(--accent),var(--accent)) calc(100% - 7px) calc(100% - 7px) / 14px 1px no-repeat,
    linear-gradient(var(--accent),var(--accent)) calc(100% - 7px) calc(100% - 7px) / 1px 14px no-repeat,
    var(--scanlines), var(--surface);
}
.system-window__heading {
  margin: 0;
  padding-bottom: 10px;
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 27%, transparent);
  color: var(--accent);
  font: 700 12px/1.5 var(--mono);
  letter-spacing: .06em;
}
.system-window p { margin: 12px 0 16px; }
.system-window__actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }

.system-gauge { --gauge: var(--system-cyan); }
.system-gauge--hp { --gauge: var(--recovery-emerald); }
.system-gauge--sanity { --gauge: var(--abyss-crimson); }
.system-gauge__caption { display: flex; justify-content: space-between; gap: 8px; font: 600 11px/1.4 var(--mono); }
.system-gauge__track { display: block; width: 100%; height: 6px; margin-top: 5px; appearance: none; border: 0; background: #162536; }
.system-gauge__track::-webkit-progress-bar { background: #162536; }
.system-gauge__track::-webkit-progress-value { background: var(--gauge); box-shadow: 0 0 8px var(--gauge); }
.system-gauge__track::-moz-progress-bar { background: var(--gauge); box-shadow: 0 0 8px var(--gauge); }

.system-rarity {
  --rarity: var(--slate-rarity);
  --frame-line: color-mix(in srgb, var(--rarity) 74%, var(--steel-panel));
  --frame-fill: var(--scanlines), linear-gradient(145deg, color-mix(in srgb,var(--rarity) 16%,var(--steel-panel)), var(--void));
  display: grid;
  gap: 12px;
  min-width: 0;
  padding: 13px 14px 12px;
}
.system-rarity--3 { --rarity: var(--system-cyan); }
.system-rarity--5 { --rarity: var(--imperial-gold); }
.system-rarity__meta { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 4px; color: var(--rarity); font: 600 11px/1.4 var(--mono); }
.system-rarity__meta span:first-child { font-size: 10px; letter-spacing: -.09em; }
.system-rarity__name { display: block; font-size: 18px; }
.system-rarity__role { color: var(--muted); font: 500 10px/1.5 var(--mono); letter-spacing: .08em; }
.system-rarity__crest {
  display: grid;
  place-items: center;
  min-height: 80px;
  color: var(--rarity);
  background: radial-gradient(ellipse, color-mix(in srgb, var(--rarity) 18%, transparent), transparent 68%);
}
.system-rarity__crest .system-icon { width: 46px; height: 46px; stroke-width: .85; filter: drop-shadow(0 0 8px currentColor); }

.system-tag {
  --tag: var(--system-cyan);
  --frame-line: color-mix(in srgb, var(--tag) 62%, var(--void));
  --frame-cut: polygon(4px 0, 100% 0, 100% calc(100% - 4px), calc(100% - 4px) 100%, 0 100%, 0 4px);
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
  padding: 1px 6px;
  color: var(--tag);
  font: 600 10px/1.35 var(--body-font);
}
.system-tag[data-tone="rest"] { --tag: #52DDB1; }
.system-tag[data-tone="panic"] { --tag: #FF839B; }
.system-tag[data-tone="promotion"] { --tag: var(--imperial-gold); }
.system-tag[data-tone="neutral"] { --tag: var(--slate-rarity); }

.system-toast {
  position: fixed;
  z-index: 80;
  bottom: var(--toast-bottom, 20px);
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100vw - 32px);
  pointer-events: none;
  opacity: 0;
  transition: opacity 170ms ease;
}
.system-toast[data-visible="true"] { opacity: 1; }
.system-toast__message {
  --frame-line: var(--system-cyan);
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 13px;
  color: #A2F5FF;
  font-size: 12px;
  text-wrap: pretty;
}

@media (prefers-reduced-motion: reduce) {
  .system-button, .system-toast { transition: none; }
}
