@import url("../fonts/fonts.css");

:root {
  color-scheme: light;
  --bg: #f6f6f6;
  --bg-panel: #ffffff;
  --bg-surface: #f8fafc;
  --line: #c2c2c2;
  --line-strong: #8b8b8c;
  --region-line: #585858;
  --text: #181818;
  --muted: #4b5563;
  --accent: #acc7eb;
  --accent-strong: #173258;
  --danger: #8b8b8c;
  --board-empty: #f3f6fb;
  --board-target: #dfeaf8;
  --board-target-line: #acc7eb;
  --board-hover: #e7edf5;
  --board-cell-line: #c7d2df;
  --solution-cell-line: rgba(24, 24, 24, 0.34);
  --solution-piece-line: rgba(24, 24, 24, 0.72);
  --shadow: 0 8px 20px rgba(24, 24, 24, 0.08);
  --docs-accent-bg: #acc7eb;
  --docs-accent-bg-hover: #b4caea;
  --docs-accent-text: #181818;
  --docs-secondary-bg: #ffffff;
  --docs-secondary-border: #c2c2c2;
  --docs-secondary-border-hover: #8b8b8c;
  --toggle-off-start: #ffffff;
  --toggle-off-end: #eef2f7;
  --toggle-thumb: #ffffff;
  --alert-bg: #f2f7fd;
  --alert-button-bg: #ffffff;
  --alert-border: rgba(23, 50, 88, 0.2);
  --alert-button-border: rgba(23, 50, 88, 0.22);
  --danger-hover-bg: #202020;
  --nexon-error-text: #7f1d1d;
  --nexon-error-border: #f0b4b4;
  --nexon-error-bg: #fff1f1;
  --nexon-selected-bg: #edf4fd;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #151515;
  --bg-panel: #202020;
  --bg-surface: #262626;
  --line: #424242;
  --line-strong: #6b7280;
  --region-line: #8f98a3;
  --text: #f2f2f2;
  --muted: #aeb7c3;
  --accent: #9fc4f3;
  --accent-strong: #cfe2ff;
  --danger: #9b9b9b;
  --board-empty: #222831;
  --board-target: #2b3f59;
  --board-target-line: #6f9dd5;
  --board-hover: #334155;
  --board-cell-line: #3b4654;
  --solution-cell-line: rgba(242, 242, 242, 0.34);
  --solution-piece-line: rgba(242, 242, 242, 0.72);
  --shadow: 0 12px 30px rgba(0, 0, 0, 0.26);
  --docs-accent-bg: #9fc4f3;
  --docs-accent-bg-hover: #b4d2f7;
  --docs-accent-text: #181818;
  --docs-secondary-bg: #262626;
  --docs-secondary-border: #4a4a4a;
  --docs-secondary-border-hover: #777777;
  --toggle-off-start: #323232;
  --toggle-off-end: #242424;
  --toggle-thumb: #f3f6fb;
  --alert-bg: #263344;
  --alert-button-bg: #202a38;
  --alert-border: rgba(159, 196, 243, 0.24);
  --alert-button-border: rgba(159, 196, 243, 0.3);
  --danger-hover-bg: #303030;
  --nexon-error-text: #fecaca;
  --nexon-error-border: #7f1d1d;
  --nexon-error-bg: #3b2020;
  --nexon-selected-bg: #263344;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Open Sans", sans-serif;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

.page-shell {
  width: min(1500px, calc(100% - 24px));
  margin: 0 auto;
  padding: 16px 0 32px;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--accent);
  text-decoration: none;
  font-weight: 800;
  font-size: 1.05rem;
  line-height: 1;
}

.back-link:hover {
  color: var(--accent);
}

.back-link img {
  width: 32px;
  height: 32px;
  object-fit: contain;
  display: block;
}

.back-link span {
  display: block;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
}

.title-block {
  min-width: 0;
}

.title-block h1 {
  margin: 0;
  margin-top: 4px;
  font-size: clamp(1.4rem, 2.5vw, 2rem);
  line-height: 1.15;
}

.title-summary {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.45;
}

.theme-toggle {
  flex: 0 0 auto;
  align-self: end;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-panel);
  box-shadow: var(--shadow);
  font-weight: 800;
}

.tool-shell {
  margin-top: 16px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-panel);
  box-shadow: var(--shadow);
}

.toolbar-panel,
.board-panel,
.piece-panel {
  padding: 14px;
}

.workspace {
  display: flex;
  gap: 16px;
  align-items: start;
  margin-top: 12px;
}

.board-panel {
  flex: 1 1 auto;
  min-width: 0;
}

.piece-panel {
  flex: 0 0 420px;
}

.panel-header h2 {
  margin: 0;
  font-size: 1rem;
}

.panel-title-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex: 1 1 0;
  min-width: 0;
  flex-wrap: wrap;
}

.compact-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.inline-caption {
  display: block;
  flex: 1 1 260px;
  min-width: 0;
  max-width: 100%;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.4;
  white-space: normal;
  overflow-wrap: anywhere;
}

.toolbar-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.toolbar-row + .toolbar-row {
  margin-top: 10px;
}

.toolbar-compact {
  justify-content: space-between;
}

.toolbar-options {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  flex-wrap: wrap;
}

.solver-alert {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 100;
  display: grid;
  gap: 10px;
  width: min(360px, calc(100vw - 36px));
  padding: 14px;
  border: 1px solid var(--alert-border);
  border-radius: 8px;
  color: var(--text);
  background: var(--alert-bg);
  box-shadow: 0 16px 36px rgba(24, 24, 24, 0.18);
}

.solver-alert[hidden] {
  display: none;
}

.solver-alert-copy {
  padding-right: 30px;
  min-width: 0;
  display: grid;
  gap: 3px;
  line-height: 1.45;
}

.solver-alert-copy strong {
  color: var(--accent-strong);
  font-size: 0.86rem;
}

.solver-alert-copy span {
  color: var(--muted);
  font-size: 0.84rem;
}

.solver-alert-button,
.solver-alert-close {
  border: 1px solid var(--alert-button-border);
  border-radius: 7px;
  color: var(--accent-strong);
  background: var(--alert-button-bg);
  font-weight: 800;
  cursor: pointer;
}

.solver-alert-button {
  justify-self: start;
  padding: 7px 9px;
  font-size: 0.82rem;
  white-space: nowrap;
}

.solver-alert-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 30px;
  height: 30px;
  padding: 0;
  font-size: 1.1rem;
  line-height: 1;
}

.solver-alert-button:hover,
.solver-alert-close:hover {
  border-color: var(--accent-strong);
}

.panel-caption {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.5;
  font-size: 0.92rem;
}

.ghost-button,
.primary-button,
.danger-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 11px;
  cursor: pointer;
  transition:
    border-color 160ms ease,
    background 160ms ease;
  white-space: nowrap;
}

.ghost-button {
  color: var(--text);
  background: var(--bg-surface);
}

.ghost-button:hover,
.primary-button:hover,
.danger-button:hover {
  border-color: var(--line-strong);
}

.toggle-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 0.9rem;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

.toggle-field input {
  position: relative;
  flex: 0 0 auto;
  width: 38px;
  height: 22px;
  margin: 0;
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  background:
    linear-gradient(180deg, var(--toggle-off-start) 0%, var(--toggle-off-end) 100%);
  box-shadow:
    inset 0 1px 2px rgba(24, 24, 24, 0.08),
    0 1px 0 rgba(255, 255, 255, 0.7);
  cursor: pointer;
  transition:
    border-color 160ms ease,
    background 160ms ease,
    box-shadow 160ms ease;
}

.toggle-field input::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  border: 1px solid rgba(24, 24, 24, 0.16);
  border-radius: 50%;
  background: var(--toggle-thumb);
  box-shadow: 0 2px 4px rgba(24, 24, 24, 0.2);
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    box-shadow 160ms ease;
}

.toggle-field input:checked {
  border-color: #86aee3;
  background:
    linear-gradient(180deg, var(--docs-accent-bg-hover) 0%, var(--docs-accent-bg) 100%);
  box-shadow:
    inset 0 1px 2px rgba(24, 24, 24, 0.12),
    0 0 0 1px rgba(172, 199, 235, 0.35);
}

.toggle-field input:checked::before {
  transform: translateX(16px);
  border-color: rgba(24, 24, 24, 0.22);
  box-shadow: 0 2px 5px rgba(24, 24, 24, 0.24);
}

.toggle-field input:focus-visible {
  outline: 3px solid rgba(172, 199, 235, 0.55);
  outline-offset: 2px;
}

.toggle-field input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.toggle-field:has(input:disabled) {
  cursor: not-allowed;
  color: var(--muted);
}

.experiment-toggle {
  position: relative;
}

.experiment-popover {
  position: absolute;
  left: 0;
  top: calc(100% + 10px);
  z-index: 20;
  width: max-content;
  max-width: min(320px, calc(100vw - 32px));
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--bg-panel);
  box-shadow: 0 14px 34px rgba(24, 24, 24, 0.18);
  font-size: 0.86rem;
  line-height: 1.45;
  white-space: normal;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(-4px);
  transition:
    opacity 140ms ease,
    transform 140ms ease,
    visibility 140ms ease;
}

.experiment-popover::before {
  content: "";
  position: absolute;
  left: 16px;
  top: -6px;
  width: 10px;
  height: 10px;
  border-left: 1px solid var(--line);
  border-top: 1px solid var(--line);
  background: var(--bg-panel);
  transform: rotate(45deg);
}

.experiment-toggle:hover .experiment-popover,
.experiment-toggle:focus-within .experiment-popover {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.primary-button {
  color: var(--docs-accent-text);
  border-color: var(--docs-accent-bg);
  background: var(--docs-accent-bg);
  font-weight: 700;
}

.danger-button {
  color: var(--text);
  border-color: var(--docs-secondary-border);
  background: var(--docs-secondary-bg);
  font-weight: 700;
}

.primary-button:hover {
  border-color: var(--docs-accent-bg-hover);
  background: var(--docs-accent-bg-hover);
}

.danger-button:hover {
  border-color: var(--docs-secondary-border-hover);
  background: var(--danger-hover-bg);
}

.danger-button:disabled,
.primary-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.piece-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.piece-row {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) 72px;
  column-gap: 16px;
  row-gap: 8px;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-surface);
}

.piece-preview {
  display: grid;
  gap: 0;
  align-self: center;
  justify-self: center;
  border: 1px solid var(--line);
}

.piece-preview-cell {
  width: 12px;
  height: 12px;
  border-radius: 0;
  border: 1px solid var(--line);
  background: var(--board-empty);
}

.piece-preview-cell.active {
  background: var(--piece-color);
  border-color: rgba(243, 240, 255, 0.18);
}

.piece-preview-cell.control {
  box-shadow: inset 0 0 0 2px rgba(24, 24, 24, 0.38);
}

.piece-meta {
  min-width: 0;
}

.piece-title {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 700;
}

.piece-input {
  width: 100%;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--bg-panel);
  color: var(--text);
  text-align: right;
}

.nexon-api-button {
  width: 100%;
  margin-top: 12px;
  border: 1px solid var(--docs-accent-bg);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--docs-accent-text);
  background: var(--docs-accent-bg);
  font-weight: 800;
  cursor: pointer;
  transition:
    border-color 160ms ease,
    background 160ms ease;
}

.nexon-api-button:hover {
  border-color: var(--docs-accent-bg-hover);
  background: var(--docs-accent-bg-hover);
}

.nexon-dialog {
  width: min(760px, calc(100% - 24px));
  max-height: min(760px, calc(100% - 24px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  background: var(--bg-panel);
  box-shadow: 0 18px 50px rgba(24, 24, 24, 0.22);
}

.nexon-dialog::backdrop {
  background: rgba(24, 24, 24, 0.42);
}

.nexon-dialog-shell {
  display: grid;
  grid-template-rows: auto auto auto auto minmax(180px, 1fr) auto;
  max-height: min(760px, calc(100vh - 24px));
  padding: 16px;
  gap: 12px;
}

.nexon-dialog-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

.nexon-dialog-header h2 {
  margin: 0;
  font-size: 1.2rem;
}

.nexon-dialog-header p {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.45;
  font-size: 0.9rem;
}

.icon-button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--bg-surface);
  cursor: pointer;
  font-size: 1.4rem;
  line-height: 1;
}

.nexon-api-controls,
.nexon-selection-controls,
.nexon-dialog-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.nexon-api-controls {
  align-items: flex-end;
}

.nexon-api-controls .primary-button {
  min-height: 38px;
}

.nexon-api-key-field {
  display: grid;
  gap: 6px;
  flex: 1 1 280px;
}

.nexon-api-key-field span {
  font-weight: 700;
  font-size: 0.9rem;
}

.nexon-api-key-label-row {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  flex-wrap: wrap;
}

.nexon-api-key-label-row a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 4px 9px;
  border: 1px solid var(--docs-secondary-border);
  border-radius: 7px;
  color: var(--accent-strong);
  background: var(--bg-surface);
  font-size: 0.82rem;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

.nexon-api-key-label-row a:hover {
  border-color: var(--docs-secondary-border-hover);
  color: var(--accent);
  background: var(--bg-panel);
}

.nexon-api-key-field input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--bg-panel);
}

.nexon-selection-count {
  margin-left: auto;
  color: var(--muted);
  font-weight: 800;
  font-size: 0.9rem;
}

.nexon-status {
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: var(--bg-surface);
  font-size: 0.9rem;
  line-height: 1.45;
}

.nexon-status.error {
  color: var(--nexon-error-text);
  border-color: var(--nexon-error-border);
  background: var(--nexon-error-bg);
}

.nexon-character-list {
  display: grid;
  gap: 8px;
  min-height: 180px;
  overflow: auto;
  padding-right: 4px;
}

.nexon-character-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-surface);
  cursor: pointer;
}

.nexon-character-row.selected {
  border-color: var(--docs-accent-bg);
  background: var(--nexon-selected-bg);
}

.nexon-character-row input {
  margin: 0;
}

.nexon-character-main {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.nexon-character-main strong,
.nexon-character-main span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nexon-character-main strong {
  font-size: 0.95rem;
}

.nexon-character-main span {
  color: var(--muted);
  font-size: 0.84rem;
}

.nexon-piece-preview {
  display: grid;
  gap: 0;
  align-self: center;
  justify-self: end;
  border: 1px solid var(--line);
  background: var(--bg-panel);
}

.nexon-piece-preview.empty {
  width: 26px;
  height: 18px;
  border-style: dashed;
}

.nexon-piece-preview-cell {
  width: 8px;
  height: 8px;
  border: 1px solid var(--line);
  background: var(--board-empty);
}

.nexon-piece-preview-cell.active {
  border-color: rgba(243, 240, 255, 0.18);
  background: var(--piece-color);
}

.nexon-piece-preview-cell.control {
  box-shadow: inset 0 0 0 1px rgba(24, 24, 24, 0.5);
}

.nexon-character-badge {
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: var(--bg-panel);
  font-size: 0.78rem;
  font-weight: 800;
  white-space: nowrap;
}

.nexon-empty {
  margin: 0;
  padding: 16px;
  color: var(--muted);
  text-align: center;
}

.nexon-dialog-actions {
  justify-content: flex-end;
}

.inline-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.inline-field span {
  font-weight: 700;
  font-size: 0.9rem;
}

.inline-field input {
  width: 80px;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--bg-panel);
  color: var(--text);
}

.inline-field select {
  min-width: 136px;
  padding: 7px 30px 7px 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--bg-panel);
  color: var(--text);
}

.inline-field small {
  color: var(--muted);
  font-size: 0.82rem;
}

.action-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.status-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.status-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-surface);
  font-size: 0.88rem;
}

.status-item span {
  color: var(--muted);
}

.status-item strong {
  font-size: 0.92rem;
}

.board-frame {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-surface);
}

.board-grid {
  display: grid;
  grid-template-columns: repeat(22, minmax(18px, 1fr));
  gap: 0;
  touch-action: none;
  border: 2px solid var(--region-line);
  overflow: hidden;
}

.board-slot-row {
  display: flex;
  justify-content: flex-start;
  gap: 8px;
  margin-top: 10px;
}

.board-slot-button {
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--bg-surface);
  font-weight: 800;
  cursor: pointer;
}

.board-slot-button.active {
  border-color: var(--docs-accent-bg);
  color: var(--docs-accent-text);
  background: var(--docs-accent-bg);
}

.board-slot-button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.board-cell {
  position: relative;
  aspect-ratio: 1 / 1;
  border: 1px solid var(--line);
  border-style: solid;
  border-radius: 0;
  border-color: var(--line);
  background: var(--board-empty);
  transition:
    background 120ms ease,
    border-color 120ms ease;
}

.board-cell.target {
  background: var(--board-target);
  border-color: var(--board-target-line);
}

.board-cell.region-hover {
  background: var(--board-hover);
}

.board-cell.solution {
  border-color: var(--solution-cell-line);
}

.board-cell.solution-control::after {
  position: absolute;
  inset: 50% auto auto 50%;
  width: clamp(20px, 96%, 34px);
  height: clamp(20px, 96%, 34px);
  background: var(--control-icon) center / contain no-repeat;
  content: "";
  filter: drop-shadow(0 1px 2px rgba(24, 24, 24, 0.36));
  image-rendering: pixelated;
  pointer-events: none;
  transform: translate(-50%, -50%);
  z-index: 1;
}

.piece-note {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.5;
}

.site-footer {
  margin-top: 18px;
  padding: 14px 4px 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.5;
  text-align: center;
}

.site-footer p {
  margin: 3px 0;
}

.site-footer a {
  color: var(--accent-strong);
  font-weight: 700;
  text-decoration: none;
}

.site-footer a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.footer-link-text {
  word-break: break-all;
}

@media (max-width: 1100px) {
  .workspace {
    flex-direction: column;
  }

  .piece-panel {
    flex-basis: auto;
    width: 100%;
  }
}

@media (max-width: 720px) {
  .page-shell {
    width: min(100% - 16px, 1500px);
    padding-top: 12px;
  }

  .topbar {
    align-items: start;
    flex-direction: column;
  }

  .piece-row {
    grid-template-columns: 44px minmax(0, 1fr) 64px;
  }

  .nexon-dialog-shell {
    padding: 12px;
  }

  .nexon-api-key-label-row {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

  .nexon-selection-count {
    width: 100%;
    margin-left: 0;
  }

  .nexon-character-row {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .nexon-piece-preview {
    grid-column: 2;
    justify-self: start;
  }

  .nexon-character-badge {
    grid-column: 2;
    justify-self: start;
  }

  .compact-header {
    display: block;
  }

  .board-grid {
    gap: 0;
  }
}
