:root {
  color-scheme: light dark;
  --board-size: 15;
  --cell-size: min(48px, 6vw);
  --line-color: #8b5a2b;
  --bg-color: #f5e4c3;
  --stone-black: #1f1f1f;
  --stone-white: #f2f2f2;
  --surface-base: rgba(255, 255, 255, 0.78);
  --surface-panel: rgba(255, 255, 255, 0.92);
  --surface-elevated: rgba(255, 255, 255, 0.98);
  --border-soft: rgba(15, 23, 42, 0.08);
  --shadow-soft: 0 24px 48px rgba(15, 23, 42, 0.18);
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: rgba(37, 99, 235, 0.16);
  --text-primary: #1f2937;
  --text-muted: #6b7280;
  --radius-lg: 20px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Meiryo, sans-serif;
  color: var(--text-primary);
  background-color: #edf2ff;
  background-image: linear-gradient(140deg, #eef2ff 0%, #e0f7ff 45%, #fef3c7 100%);
  background-attachment: fixed;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(1rem, 3vw, 3rem);
  line-height: 1.5;
}

.app {
  position: relative; /* anchors toggle + gear */
  display: flex;
  flex-direction: column;
  gap: clamp(1.5rem, 2.2vw, 2.2rem);
  padding: clamp(1.75rem, 2.5vw, 2.75rem);
  background: var(--surface-base);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(24px) saturate(140%);
  border: 1px solid var(--border-soft);
  box-shadow: var(--shadow-soft);
  max-width: min(1250px, 100%);
  width: 100%;
  overflow: hidden;
}

.app-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
  text-align: center;
}

.app-sidebar {
  position: fixed;
  top: clamp(1.5rem, 4vh, 3rem);
  left: clamp(1rem, 4vw, 3.2rem);
  width: min(320px, calc(100vw - 3rem));
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.35rem 1.5rem;
  background: var(--surface-panel);
  color: var(--text-primary);
  backdrop-filter: blur(18px) saturate(160%);
  border-radius: 18px;
  border: 1px solid var(--border-soft);
  box-shadow: 0 26px 48px rgba(15, 23, 42, 0.18);
  transition: transform 0.25s ease, opacity 0.25s ease;
  transform: translateY(-20px) scale(0.98);
  opacity: 0;
  pointer-events: none;
  z-index: 140;
}

.sidebar-user {
  display: grid;
  gap: 0.25rem;
  font-size: 0.9rem;
  text-align: left;
}

.sidebar-username {
  font-weight: 600;
  word-break: break-all;
}

.sidebar-auth-btn,
.sidebar-stats-btn {
  padding: 0.75rem 1.35rem;
  border-radius: 999px;
  border: none;
  background: linear-gradient(135deg, var(--accent), #3b82f6);
  color: #fff;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  box-shadow: 0 14px 32px rgba(37, 99, 235, 0.28);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.sidebar-auth-btn:hover,
.sidebar-auth-btn:focus-visible,
.sidebar-stats-btn:hover,
.sidebar-stats-btn:focus-visible {
  transform: translateY(-1px);
  box-shadow: 0 16px 38px rgba(37, 99, 235, 0.32);
}

.sidebar-auth-btn:active,
.sidebar-stats-btn:active {
  transform: translateY(1px);
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.25);
}

.sidebar-stats-btn {
  margin-top: 1rem;
}

.sidebar-toggle {
  position: absolute;
  top: 1rem;
  left: 1rem;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid var(--border-soft);
  background: var(--surface-elevated);
  color: var(--text-primary);
  font-size: 1.2rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 12px 26px rgba(15, 23, 42, 0.12);
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
  z-index: 110;
}

.sidebar-toggle:hover {
  transform: translateY(-1px);
  box-shadow: 0 16px 30px rgba(15, 23, 42, 0.14);
}

.sidebar-toggle:active {
  transform: translateY(1px);
  box-shadow: 0 9px 18px rgba(15, 23, 42, 0.12);
}

.sidebar-toggle:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.4);
  outline-offset: 3px;
}

.sidebar-toggle[aria-expanded="true"] {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 20px 36px rgba(37, 99, 235, 0.3);
}

.sidebar-toggle[aria-expanded="true"]:hover {
  background: var(--accent-hover);
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  backdrop-filter: blur(4px);
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;
  z-index: 120;
}

.app--sidebar-open .app-sidebar {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: auto;
}

.app--sidebar-open .sidebar-backdrop {
  opacity: 1;
  pointer-events: auto;
}

h1 {
  margin: 0;
  font-size: clamp(1.8rem, 1.4rem + 1vw, 2.45rem);
  font-weight: 700;
  letter-spacing: 0.08em;
}

#status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  margin: 0;
  padding: 0.45rem 1.15rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  font-size: 1rem;
  box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.2);
}

.controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.25rem;
  color: var(--text-muted);
}

.auth-card {
  margin: 0 auto;
  padding: 1.2rem 1.4rem;
  max-width: 380px;
  background: var(--surface-panel);
  border-radius: 18px;
  border: 1px solid var(--border-soft);
  box-shadow: 0 18px 32px rgba(15, 23, 42, 0.18);
  text-align: left;
}

.auth-dialog {
  position: fixed;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  width: min(92vw, 420px);
  background: var(--surface-elevated);
  border-radius: 20px;
  border: 1px solid var(--border-soft);
  box-shadow: 0 28px 48px rgba(15, 23, 42, 0.28);
  padding: 1.25rem 1.5rem 1.75rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  z-index: 200;
}

.auth-dialog[hidden],
.modal-backdrop[hidden] {
  display: none !important;
}

.auth-dialog__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.auth-dialog__header h2 {
  margin: 0;
  font-size: 1.25rem;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(6px);
  z-index: 150;
}

.auth-user {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.auth-view {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.auth-username {
  font-weight: 600;
}

.auth-toggle {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.25rem;
  background: var(--surface-panel);
  border-radius: 999px;
  border: 1px solid var(--border-soft);
  padding: 0.2rem;
}

.auth-toggle__option {
  border: none;
  border-radius: 999px;
  padding: 0.45rem 0.75rem;
  font-weight: 600;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.auth-toggle__option.is-active {
  background: linear-gradient(135deg, var(--accent), #3b82f6);
  color: #fff;
  box-shadow: 0 10px 22px rgba(37, 99, 235, 0.28);
}

.auth-toggle__option:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.35);
}

.auth-logout {
  border: none;
  background: #e65f5f;
  color: #fff;
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s ease;
}

.auth-logout:hover,
.auth-logout:focus-visible {
  background: #d64c4c;
}

.user-stats {
  margin-bottom: 0.75rem;
  padding: 0.75rem;
  background: rgba(79, 140, 255, 0.08);
  border: 1px solid rgba(79, 140, 255, 0.25);
  border-radius: 10px;
  color: #1c2230;
}

.stats-dialog {
  position: fixed;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  width: min(92vw, 480px);
  background: var(--surface-elevated);
  border-radius: 20px;
  border: 1px solid var(--border-soft);
  box-shadow: 0 28px 48px rgba(15, 23, 42, 0.32);
  padding: 1.25rem 1.75rem 1.6rem;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  z-index: 210;
}

.stats-dialog[hidden] {
  display: none !important;
}

.stats-dialog__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.stats-card {
  margin: 0;
}

.user-stats__title {
  margin: 0 0 0.5rem;
  font-size: 1.05rem;
  font-weight: 600;
}

.user-stats__summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.4rem 0.75rem;
  margin: 0 0 0.75rem;
  padding: 0;
}

.user-stats__summary-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
}

.user-stats__summary-item dt {
  font-weight: 600;
}

.user-stats__summary-item dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
}

.user-stats__modes {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
}

.user-stats__mode {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  margin: 0;
  font-size: 0.95rem;
}

.user-stats__mode-label {
  font-weight: 600;
}

.user-stats__recent-block {
  margin-bottom: 0.75rem;
}

.user-stats__subtitle {
  margin: 0 0 0.3rem;
  font-size: 0.95rem;
  font-weight: 600;
}

.user-stats__recent {
  margin: 0;
  padding-left: 1.1rem;
  display: grid;
  gap: 0.25rem;
  font-size: 0.9rem;
}

.user-stats__empty {
  margin: 0;
  font-size: 0.9rem;
  color: #4f5b6d;
}

.auth-tabs {
  display: inline-flex;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.06);
  padding: 0.2rem;
  margin-bottom: 0.8rem;
}

.auth-tab {
  border: none;
  background: transparent;
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
  color: #555;
  transition: background 0.2s ease, color 0.2s ease;
}

.auth-tab.is-active {
  background: #4f8cff;
  color: #fff;
}

.auth-form {
  display: grid;
  gap: 0.6rem;
  margin-bottom: 0.5rem;
}

.auth-field {
  display: grid;
  gap: 0.25rem;
  font-size: 0.9rem;
}

.auth-field input {
  padding: 0.5rem 0.6rem;
  border-radius: 6px;
  border: 1px solid rgba(0, 0, 0, 0.2);
  font-size: 1rem;
}

.auth-field input:focus-visible {
  outline: 2px solid #4f8cff;
  outline-offset: 2px;
}

.auth-submit {
  justify-self: end;
  border: none;
  border-radius: 6px;
  padding: 0.45rem 1.2rem;
  background: linear-gradient(135deg, #4f8cff, #7aa8ff);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.auth-submit:hover,
.auth-submit:focus-visible {
  transform: translateY(-1px);
  box-shadow: 0 6px 14px rgba(79, 140, 255, 0.35);
}

.auth-message {
  min-height: 1.4em;
  font-size: 0.85rem;
  margin: 0;
  color: #444;
}

.auth-message.error {
  color: #d64c4c;
}

.auth-note {
  font-size: 0.8rem;
  color: #666;
  margin: 0;
}

.auth-note[hidden] {
  display: none;
}

/* Modern switch toggle */
.switch {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  user-select: none;
}

.switch input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.switch .slider {
  --w: 44px;
  --h: 26px;
  --p: 3px;
  position: relative;
  width: var(--w);
  height: var(--h);
  background: #cfd3d8;
  border-radius: 999px;
  transition: background 0.2s ease;
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.15);
}

.switch .slider::before {
  content: "";
  position: absolute;
  left: var(--p);
  top: var(--p);
  width: calc(var(--h) - var(--p) * 2);
  height: calc(var(--h) - var(--p) * 2);
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,0.25);
  transition: transform 0.2s ease;
}

.switch input:checked + .slider {
  background: #4f8cff;
}

.switch input:checked + .slider::before {
  transform: translateX(calc(var(--w) - var(--h)));
}

.switch input:focus-visible + .slider {
  outline: 3px solid rgba(79, 140, 255, 0.6);
  outline-offset: 2px;
}

.switch .switch-label {
  font-size: 0.95rem;
}

.play-area {
  display: grid;
  grid-template-columns: minmax(0, auto) minmax(220px, 1fr);
  align-items: center;
  justify-content: center;
  gap: clamp(1.5rem, 3vw, 2.4rem);
  margin-bottom: 1rem;
  width: 100%;
}

.board {
  display: grid;
  grid-template-columns: repeat(var(--board-size), var(--cell-size));
  grid-template-rows: repeat(var(--board-size), var(--cell-size));
  background: linear-gradient(135deg, #f6e7c5, #e0bd7e);
  border: 1px solid rgba(167, 114, 59, 0.45);
  border-radius: 18px;
  box-shadow: 0 20px 40px rgba(167, 114, 59, 0.22), inset 0 0 0 1px rgba(255, 255, 255, 0.35);
  margin: 0 auto;
  touch-action: manipulation;
}

.vrm-viewer {
  width: clamp(240px, 30vw, 380px);
  height: clamp(320px, 44vw, 560px);
  background: radial-gradient(140% 140% at 20% 15%, rgba(37, 99, 235, 0.18) 0%, rgba(59, 130, 246, 0.35) 55%, rgba(255, 255, 255, 0.35) 100%);
  border: 1px solid var(--border-soft);
  border-radius: 22px;
  box-shadow: 0 24px 48px rgba(15, 23, 42, 0.2);
  position: relative;
  overflow: hidden;
  backdrop-filter: blur(18px) saturate(150%);
}

/* --- VRM: speech bubble overlay --- */
.vrm-viewer .vrm-chat-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.vrm-viewer .vrm-bubble {
  position: absolute;
  max-width: 78%;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.92);
  color: #1d1d1d;
  font-size: 0.95rem;
  line-height: 1.35;
  box-shadow: 0 6px 18px rgba(0,0,0,0.18);
  opacity: 0;
  transform: translateY(6px) scale(0.98);
  transition: opacity 160ms ease, transform 160ms ease;
}

.vrm-viewer .vrm-bubble.show {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.vrm-viewer .vrm-bubble::after {
  content: "";
  position: absolute;
  left: 18px; /* 左寄せデフォルト */
  bottom: -10px; /* 下向きのしっぽ */
  border-width: 10px 10px 0 0;
  border-style: solid;
  border-color: rgba(255, 255, 255, 0.92) transparent transparent transparent;
  filter: drop-shadow(0 3px 2px rgba(0,0,0,0.12));
}

/* 位置プリセット */
.vrm-viewer .vrm-bubble.pos-head-left { left: 8%; top: 10%; right: auto; bottom: auto; }
.vrm-viewer .vrm-bubble.pos-head-right { right: 8%; top: 10%; left: auto; bottom: auto; }
.vrm-viewer .vrm-bubble.pos-bottom-left { left: 8%; bottom: 12%; right: auto; top: auto; }
.vrm-viewer .vrm-bubble.pos-bottom-right { right: 8%; bottom: 12%; left: auto; top: auto; }

/* 右寄せのしっぽ位置 */
.vrm-viewer .vrm-bubble.pos-head-right::after,
.vrm-viewer .vrm-bubble.pos-bottom-right::after {
  left: auto;
  right: 18px;
  border-width: 10px 0 0 10px;
  border-color: rgba(255, 255, 255, 0.92) transparent transparent transparent;
}

/* サイズプリセット */
.vrm-viewer .vrm-bubble.size-small { font-size: 0.85rem; padding: 8px 10px; max-width: 68%; }
.vrm-viewer .vrm-bubble.size-normal { font-size: 0.95rem; padding: 10px 12px; max-width: 78%; }
.vrm-viewer .vrm-bubble.size-large { font-size: 1.05rem; padding: 12px 14px; max-width: 84%; }

@media (prefers-color-scheme: dark) {
  .vrm-viewer .vrm-bubble {
    background: rgba(20, 22, 26, 0.92);
    color: #f2f5f8;
  }
  .vrm-viewer .vrm-bubble::after {
    border-color: rgba(20, 22, 26, 0.92) transparent transparent transparent;
  }
}

/* --- VRM: chat log at bottom --- */
.vrm-viewer .vrm-chat-log {
  position: absolute;
  left: 6%;
  right: 6%;
  bottom: 6%;
  max-height: 38%;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
}

.vrm-viewer .vrm-log-item {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.55);
  color: #222;
  padding: 4px 8px;
  border-radius: 10px;
  font-size: 0.85rem;
  line-height: 1.3;
  box-shadow: 0 2px 10px rgba(0,0,0,0.15);
  opacity: 0;
  transform: translateY(6px);
  animation: vrmLogIn 180ms ease forwards;
}

@media (prefers-color-scheme: dark) {
  .vrm-viewer .vrm-log-item {
    background: rgba(20, 22, 26, 0.55);
    color: #f2f5f8;
  }
}

@keyframes vrmLogIn {
  to { opacity: 0.95; transform: translateY(0); }
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  border: 1px solid rgba(0, 0, 0, 0.2);
  background: transparent;
  padding: 0;
  font: inherit;
  color: inherit;
  position: relative;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cell:focus-visible {
  outline: 3px solid rgba(255, 206, 84, 0.8);
  outline-offset: -3px;
}

.cell[data-filled="true"] {
  cursor: not-allowed;
}

.cell::before {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 80%;
  height: 80%;
  border-radius: 50%;
  opacity: 0;
  transform: scale(0.9);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.cell.black::before {
  background: var(--stone-black);
  box-shadow: inset 0 -4px 6px rgba(255, 255, 255, 0.25);
  opacity: 1;
  transform: scale(1);
}

.cell.white::before {
  background: var(--stone-white);
  box-shadow: inset 0 -3px 5px rgba(0, 0, 0, 0.25);
  opacity: 1;
  transform: scale(1);
}

.cell.win::before {
  outline: 4px solid #ffce54;
}

#reset {
  font-size: 1rem;
  border: none;
  background: linear-gradient(135deg, #f97316, #facc15);
  color: #fff;
  padding: 0.65rem 1.85rem;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
  letter-spacing: 0.02em;
  box-shadow: 0 16px 30px rgba(249, 115, 22, 0.28);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.btn-secondary {
  margin-left: 0.75rem;
  font-size: 0.95rem;
  padding: 0.45rem 1rem;
  border-radius: 999px;
  background: var(--surface-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-soft);
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.14);
  transition: transform 0.15s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.btn-secondary:hover {
  background: var(--surface-panel);
  transform: translateY(-1px);
  box-shadow: 0 12px 26px rgba(15, 23, 42, 0.16);
}

.btn-secondary:active {
  transform: translateY(1px);
  box-shadow: 0 7px 16px rgba(15, 23, 42, 0.12);
}

#reset:hover {
  transform: translateY(-1px);
  box-shadow: 0 20px 36px rgba(249, 115, 22, 0.32);
}

#reset:active {
  transform: translateY(1px);
  box-shadow: 0 8px 16px rgba(249, 115, 22, 0.28);
}

@media (max-width: 960px) {
  .play-area {
    grid-template-columns: 1fr;
    justify-items: center;
    gap: 1.75rem;
  }

  .vrm-viewer {
    width: min(340px, 70vw);
    height: clamp(280px, 60vw, 460px);
  }
}

@media (max-width: 640px) {
  .app {
    padding: clamp(1.25rem, 6vw, 1.6rem);
  }

  .sidebar-toggle {
    top: 0.75rem;
    left: 0.75rem;
    width: 38px;
    height: 38px;
  }

  .options-gear {
    top: 0.75rem;
    right: 0.75rem;
    width: 38px;
    height: 38px;
  }

  .app-sidebar {
    left: 50%;
    width: min(90vw, 360px);
    transform: translate(-50%, -20px) scale(0.98);
  }

  .app--sidebar-open .app-sidebar {
    transform: translate(-50%, 0) scale(1);
  }

  .play-area {
    gap: 1.5rem;
  }

  #status {
    width: 100%;
  }
}

/* ---- Options panel ---- */
.options-panel {
  position: fixed !important; /* popup center */
  left: 50% !important;
  top: 50% !important;
  transform: translate(-50%, -50%) !important;
  width: min(92vw, 720px);
  max-height: 80vh;
  overflow: auto;
  background: var(--surface-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-soft);
  border-radius: 20px;
  box-shadow: 0 28px 48px rgba(15, 23, 42, 0.32);
  padding: 1.25rem 1.5rem;
  z-index: 99999;
}

.options-panel[hidden],
.options-backdrop[hidden] {
  display: none !important;
}

.options-backdrop {
  position: fixed !important;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(6px);
  z-index: 99998;
}

.options-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.options-header h2 {
  font-size: 1.05rem;
  margin: 0.2rem 0 0.4rem 0.2rem;
}

.icon-close {
  border: none;
  background: var(--surface-panel);
  font-size: 1.25rem;
  line-height: 1;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-muted);
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.12);
  transition: transform 0.15s ease, box-shadow 0.18s ease, background 0.18s ease, color 0.18s ease;
}

.icon-close:hover {
  transform: translateY(-1px);
  background: var(--surface-elevated);
  color: var(--text-primary);
  box-shadow: 0 14px 32px rgba(15, 23, 42, 0.16);
}

.icon-close:active {
  transform: translateY(1px);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.12);
}

.options-content {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.opt-group {
  border: 1px solid var(--border-soft);
  border-radius: 16px;
  padding: 0.85rem 1rem;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 14px 26px rgba(15, 23, 42, 0.12);
}

.opt-group legend {
  padding: 0 8px;
  color: var(--text-primary);
  font-weight: 600;
}

.opt-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0.35rem 0;
}

.opt-row.-stack {
  display: block;
}

.opt-row input[type="number"] { width: 8rem; }
.opt-row select { min-width: 10rem; }
.opt-row textarea { width: 100%; }

@media (prefers-color-scheme: dark) {
  .options-panel {
    background: rgba(24, 30, 44, 0.95);
    color: #f2f5f8;
    border-color: rgba(99, 110, 133, 0.4);
    box-shadow: 0 24px 48px rgba(0, 0, 0, 0.45);
  }
  .options-gear {
    background: rgba(48, 58, 84, 0.9);
    color: #e5e9f0;
    border-color: rgba(99, 110, 133, 0.45);
    box-shadow: 0 14px 32px rgba(0, 0, 0, 0.45);
  }
  .options-gear:hover {
    background: rgba(58, 70, 100, 0.95);
  }
  .options-gear:active {
    background: rgba(48, 58, 84, 0.78);
    box-shadow: 0 9px 18px rgba(0, 0, 0, 0.45);
  }
  .opt-group {
    border-color: rgba(99, 110, 133, 0.4);
    background: rgba(35, 43, 63, 0.85);
  }
  .icon-close {
    color: #e5e9f0;
  }
  .btn-secondary {
    background: rgba(48, 58, 84, 0.85);
    color: #e5e9f0;
    border-color: rgba(99, 110, 133, 0.45);
    box-shadow: 0 12px 26px rgba(0, 0, 0, 0.45);
  }
  .btn-secondary:hover {
    background: rgba(58, 70, 100, 0.9);
  }
  .btn-secondary:active {
    background: rgba(48, 58, 84, 0.75);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.4);
  }
}
.options-gear {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid var(--border-soft);
  background: var(--surface-elevated);
  color: var(--text-primary);
  font-size: 1.2rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 12px 26px rgba(15, 23, 42, 0.12);
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
  z-index: 110;
}

.options-gear:hover {
  transform: translateY(-1px);
  background: var(--surface-panel);
  box-shadow: 0 16px 32px rgba(15, 23, 42, 0.16);
}

.options-gear:active {
  transform: translateY(1px);
  box-shadow: 0 9px 18px rgba(15, 23, 42, 0.12);
}

.options-gear:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.4);
  outline-offset: 3px;
}
