@font-face {
  font-family: 'lichess';
  font-display: block;
  src: url('./assets/font/lichess.woff2') format('woff2');
}

[data-icon]::before {
  content: attr(data-icon);
  font-family: 'lichess' !important;
  font-style: normal;
  font-weight: normal;
  font-variant: normal;
  text-transform: none;
  line-height: 1;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body,
html {
  margin: 0;
  padding: 0;
  height: 100dvh;
  width: 100vw;
  font-family: 'Noto Sans', 'Lucida Grande', sans-serif;
  overflow: hidden;
  background: #161512;
  color: #bababa;
}

#app {
  display: flex;
  height: 100%;
  width: 100%;
}

body.not-logged-in #sidebar-pane,
body.not-logged-in #left-pane> :not(.editor-toolbar),
body.not-logged-in #right-pane,
body.not-logged-in #resizer {
  display: none !important;
}

body.not-logged-in #left-pane {
  flex: 1 !important;
  justify-content: center;
  align-items: center;
  background: radial-gradient(circle at center, #1e1c1a 0%, #161512 100%);
}

/* Auth UI */
#cv-auth-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100dvh;
  background: #1a1a1a;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 2000000;
}

#cv-login-card {
  background: #2c2c2c;
  padding: 2.5rem;
  border-radius: 12px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
  width: 100%;
  max-width: 360px;
  text-align: center;
  color: white;
}

#cv-login-card h2 {
  margin-bottom: 2rem;
  font-weight: 300;
  letter-spacing: 1px;
}

#cv-login-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

#cv-login-form input {
  padding: 0.8rem;
  border-radius: 6px;
  border: 1px solid #444;
  background: #333;
  color: white;
  font-size: 1rem;
}

#cv-login-form button {
  padding: 0.8rem;
  border-radius: 6px;
  border: none;
  background: #03a9f4;
  color: white;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  transition: background 0.2s;
}

#cv-login-form button:hover {
  background: #0288d1;
}

.pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: auto;
}

#sidebar-pane {
  flex: 0 0 250px;
  background: #1e1c1a;
  border-right: 1px solid #333;
  padding: 10px;
  display: flex;
  flex-direction: column;
  transition: all 0.2s ease;
  overflow: hidden;
}

#sidebar-pane.collapsed {
  flex: 0 0 0;
  padding: 0;
  border-right: none;
}

#left-pane {
  flex: 1;
  border-right: 1px solid #333;
  padding: 10px;
  display: flex;
  flex-direction: column;
}

.editor-toolbar {
  display: flex;
  gap: 10px;
  padding-bottom: 10px;
}

.editor-toolbar button {
  background: #333;
  color: #bababa;
  border: 1px solid #4d4d4d;
  padding: 5px 10px;
  cursor: pointer;
  border-radius: 3px;
}

.editor-toolbar button:hover {
  background: #4a9ff5;
  color: white;
}

/* Dropdown Menu Styles */
.dropdown {
  position: relative;
  display: inline-block;
}

.dropbtn {
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
}

.dropdown-content {
  display: none;
  position: absolute;
  background-color: #2b2927;
  min-width: 160px;
  box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.5);
  z-index: 1000;
  border: 1px solid #4d4d4d;
  border-radius: 4px;
  top: 100%;
}

.dropdown-content button {
  color: #bababa;
  padding: 8px 12px;
  text-decoration: none;
  display: block;
  width: 100%;
  text-align: left;
  border: none !important;
  background: none !important;
  border-radius: 0 !important;
}

.dropdown-content button:hover {
  background-color: #4a9ff5 !important;
  color: white !important;
}

.dropdown:hover .dropdown-content {
  display: block;
}

:root {
  --editor-height: 50%;
  --tools-width: 400px;
  --tools-height: 450px;
  --board-scale-x: 1;
  --board-scale-y: 1;
}

.md-editor {
  width: 100%;
  height: var(--editor-height);
  flex-shrink: 0;
  background: #2b2927;
  color: #bababa;
  border: 1px solid #4d4d4d;
  resize: none;
  font-family: monospace;
  padding: 10px;
  box-sizing: border-box;
  transition: height 0.3s ease;
}

.md-editor.collapsed {
  display: none;
}

.md-viewer {
  flex: 1;
  padding-top: 20px;
  overflow: auto;
}

.fen-link {
  background: #3692e7;
  color: white;
  border: none;
  border-radius: 3px;
  padding: 2px 5px;
  cursor: pointer;
  margin: 2px;
}

.fen-link:hover {
  background: #4a9ff5;
}

.fen-box {
  cursor: pointer;
  transition: opacity 0.2s;
}

.fen-box:hover {
  opacity: 0.8;
}

#resizer {
  flex: 0 0 5px;
  background-color: #333;
  cursor: col-resize;
  z-index: 10;
  transition: background-color 0.2s;
}

#resizer:hover,
#resizer.active {
  background-color: #4a9ff5;
}

.event-box {
  display: inline-block;
  width: fit-content;
  background-color: #007aff;
  color: white;
  padding: 2px 10px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: bold;
  margin-bottom: 5px;
  cursor: pointer;
  transition: all 0.2s;
  border: none;
}

.event-box:hover {
  opacity: 0.8;
}

.event-box.no-export {
  background-color: #ffebee !important;
  color: #c62828 !important;
  border: 1px solid #ffcdd2 !important;
}

.event-box.no-export:hover {
  background-color: #ffcdd2 !important;
}

#right-pane {
  background: #161512;
  flex: 1;
  min-width: 0;
}

.analyse {
  display: flex;
  height: 100%;
  width: 100%;
  align-items: center;
  justify-content: center;
  gap: 20px;
  overflow: hidden;
  min-width: 0;
}

/* Vertical Layout Modifier */
.analyse--vertical {
  flex-direction: column;
  overflow-y: auto;
  justify-content: flex-start;
  padding: 10px 0;
}

.analyse--vertical .puzzle-board-container {
  max-width: min(100%, calc(100dvh - var(--tools-height) - 50px));
  width: 95%;
  margin-bottom: 10px;
}

.analyse--vertical .analyse__tools {
  width: 95%;
  height: var(--tools-height);
  min-height: 200px;
  max-height: 80dvh;
}

.cg-board-wrap {
  width: 100%;
  max-width: calc(100dvh - 40px);
  aspect-ratio: 1 / 1;
  flex-shrink: 1;
  min-width: 0;
  min-height: 0;
}

.cg-wrap square.check {
  background: radial-gradient(ellipse at center, rgba(255, 0, 0, 1) 0%, rgba(255, 0, 0, 0) 80%);
}

.analyse__menu {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  padding: 4px 10px;
  background: #2b2927;
  border-bottom: 1px solid #3d3b39;
  z-index: 10;
}

.analyse__menu-actions {
  display: flex;
  gap: 8px;
}

.board-action {
  background: #2b2927;
  color: #bababa;
  border: 1px solid #3d3b39;
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
  height: 26px;
}

.board-action:hover {
  background: #3d3b39;
  border-color: #4d4b49;
  color: #fff;
}

.board-action.active {
  background: #629924;
  border-color: #629924;
  color: #fff;
}

.board-action .icon {
  font-size: 16px;
}

.board-action .label {
  font-weight: 500;
}

.analyse__tools {
  width: var(--tools-width);
  height: 100%;
  max-height: calc(100dvh - 40px);
  background: #262421;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: scale(var(--board-scale-x), var(--board-scale-y));
  transform-origin: center center;
}

.tview2 {
  flex: 1;
  overflow-y: auto;
  padding: 0;
  background: #2b2927;
  border-bottom: 1px solid #3d3b39;
  font-size: 15px;
  line-height: 1.6;
  white-space: normal;
  user-select: none;
}

.tview2-inline {
  display: block;
  padding: 7px 3px 7px 7px;
}

.tview2-inline .mainline {
  font-weight: bold;
}

/* Move element — Lichess uses inline-block */
.tview2 move {
  display: inline-block;
  cursor: pointer;
  padding: 0.25em 0.17em;
  /* Match Lichess 13px/1.092em */
  color: #bababa;
  margin-inline-end: 2px;
}

.tview2 comment {
  font-style: italic;
  color: #7a7a7a;
  font-size: 0.95em;
  padding: 0 0.3em;
  white-space: normal;
  display: inline;
}

.tview2 move.active comment {
  color: rgba(255, 255, 255, 0.7);
}

.tview2 move:hover {
  background: rgba(255, 255, 255, 0.08);
}

.tview2 move.active {
  background: #3692e7;
  color: #fff;
  border-radius: 3px;
}

.tview2 move.mainline {
  font-weight: 600;
}

/* Move index (turn number) */
.tview2 move index {
  font-size: 90%;
  color: #9a9a9a;
  padding-inline-end: 0.2em;
  line-height: 111.11%;
}

/* SAN notation */
.tview2 san {
  display: inline;
}

/* Variations container */
.tview2 interrupt {
  display: inline;
}

.tview2 lines {
  display: inline;
}

.tview2 line {
  display: block;
}

/* Context Menu */
#analyse-cm {
  user-select: none;
}

#analyse-cm .action:hover {
  background: #3692e7;
  color: #fff !important;
}

#analyse-cm .action span {
  font-size: 1.2em;
  vertical-align: middle;
}

/* Variation line styling — wrapped in parentheses look */
.tview2 line::before {
  content: '(';
  color: #787878;
  font-size: 0.9em;
}

.tview2 line::after {
  content: ') ';
  color: #787878;
  font-size: 0.9em;
}

/* Variation moves are slightly dimmer */
.tview2 line move {
  color: #a0a0a0;
}

.tview2 line move:hover {
  color: #d0d0d0;
  background: rgba(255, 255, 255, 0.06);
}

.tview2 line move.active {
  color: #fff;
  background: #3692e7;
}

/* Nested variations are even dimmer */
.tview2 line line move {
  color: #888;
  font-size: 0.95em;
}

/* Ceval UI Styles — Lichess-accurate */
.ceval-wrap {
  flex-shrink: 0;
  width: 100%;
  box-sizing: border-box;
}

.ceval {
  position: relative;
  display: flex;
  column-gap: 6px;
  align-items: stretch;
  padding-top: 3px;
  /* space for bar */
  background: #262421;
  width: 100%;
  box-sizing: border-box;
}

.ceval .cmn-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 40px;
  margin-inline-start: 6px;
}

/* cmn-toggle — Lichess toggle switch */
.cmn-toggle input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.cmn-toggle label {
  display: block;
  position: relative;
  cursor: pointer;
  outline: none;
  padding: 1px;
  width: 40px;
  height: 24px;
  border: 1px solid #3d3b39;
  border-radius: 24px;
  background-clip: padding-box;
  background-color: #4d4d4d;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: background 0.2s ease, box-shadow 0.2s ease;
}

.cmn-toggle label::after {
  display: block;
  position: absolute;
  content: '';
  width: 20px;
  height: 20px;
  bottom: 1px;
  left: 1px;
  border-radius: 100%;
  background: linear-gradient(to bottom, #7a7a7a, #5a5a5a);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 0 1px rgba(255, 255, 255, 0.1) inset;
  transition: margin 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.cmn-toggle input:checked+label {
  background-color: #629924;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.2), 0 0 6px rgba(98, 153, 36, 0.3);
}

.cmn-toggle input:checked+label::after {
  margin-inline-start: 16px;
  background: linear-gradient(to bottom, #ccc, #aaa);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3), 0 0 1px rgba(255, 255, 255, 0.2) inset;
}

.cmn-toggle input:focus-visible:not(:disabled)+label {
  box-shadow: 0 0 8px rgba(98, 153, 36, 0.5);
  border-color: #629924;
}

.ceval pearl {
  flex: 1 0 auto;
  line-height: 38px;
  font-size: 1.6em;
  text-align: center;
  font-weight: bold;
  color: #e0e0e0;
}

.ceval pearl i {
  display: inline-block;
}

.ceval pearl i.ddloader {
  width: 20px;
  height: 20px;
  border: 2px solid #555;
  border-top-color: #bababa;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.ceval .engine {
  flex: 2 1 auto;
  font-size: 12px;
  line-height: 16px;
  margin-top: 3px;
  color: #8c8c8c;
  user-select: none;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.ceval .engine span {
  font-weight: bold;
  color: #bababa;
}

.ceval .engine .technology {
  margin-inline-start: 5px;
  font-weight: normal;
  font-size: 11px;
}

.ceval .engine .technology.good {
  color: #629924;
}

.ceval .engine .info {
  display: block;
  white-space: nowrap;
  font-weight: normal;
  color: #8c8c8c;
}

/* Progress bar */
.ceval .bar {
  position: absolute;
  width: 100%;
  height: 3px;
  top: 0;
  left: 0;
}

.ceval .bar span {
  display: block;
  height: 3px;
  width: 0;
  background: #629924;
  transition: width 1s;
}

/* Gear button */
.ceval__gear {
  flex: 0 0 auto;
  background: none;
  border: none;
  color: #8c8c8c;
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 38px;
  transition: color 0.15s ease;
}

.ceval__gear:hover,
.ceval__gear.active {
  color: #bababa;
}

/* Ceval settings panel — Lichess-accurate */
#ceval-settings-anchor {
  position: relative;
}

#ceval-settings {
  position: absolute;
  right: 0;
  top: 0;
  z-index: 100;
  min-width: 220px;
  background: #1f1e1c;
  border: 1px solid #3d3b39;
  border-radius: 4px;
  padding: 12px 16px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
}

#ceval-settings .setting {
  margin-bottom: 12px;
}

#ceval-settings .setting:last-child {
  margin-bottom: 0;
}

#ceval-settings .setting label {
  display: block;
  font-size: 13px;
  color: #bababa;
  margin-bottom: 6px;
  user-select: none;
}

#ceval-settings .setting input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  background: #3d3b39;
  border-radius: 3px;
  outline: none;
  cursor: pointer;
}

#ceval-settings .setting input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: linear-gradient(to bottom, #aaa, #888);
  border: 1px solid #555;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  cursor: pointer;
}

#ceval-settings .setting input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: linear-gradient(to bottom, #aaa, #888);
  border: 1px solid #555;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  cursor: pointer;
}

#ceval-settings .range_value {
  text-align: right;
  font-size: 12px;
  color: #8c8c8c;
  margin-top: 4px;
}

/* PV box — Lichess-accurate */
.pv_box {
  position: relative;
  background: #262421;
  font-size: 13px;
}

.pv_box .pv {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  line-height: 2em;
  border-top: 1px solid #3d3b39;
  padding-inline-end: 14px;
  min-height: 2em;
}

.pv_box .pv.pv--nowrap {
  display: block;
  flex-wrap: initial;
  height: 2em;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.pv_box .pv strong {
  display: inline-block;
  width: 34px;
  text-align: center;
  color: #bababa;
  font-size: 13px;
}

.pv_box .pv span {
  margin-inline-start: 4px;
  color: #8c8c8c;
  cursor: default;
}

.pv_box .pv span.pv-san {
  cursor: pointer;
  color: #bababa;
}

.pv_box .pv span.pv-san:hover {
  color: #3692e7;
}

.pv_box .pv[data-uci]:hover {
  background: rgba(54, 146, 231, 0.1);
  cursor: pointer;
}

/* Scrubber Controls Styles */
.analyse__controls {
  padding: 10px;
  background: #1e1c1a;
  display: flex;
  justify-content: center;
  flex-shrink: 0;
}

.jumps {
  display: flex;
  gap: 2px;
}

.fbt.move {
  background: #333;
  color: #bababa;
  border: none;
  border-radius: 3px;
  padding: 8px 12px;
  font-family: monospace;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.fbt.move:hover {
  background: #4a9ff5;
  color: #fff;
}

.fbt.move.disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.fbt.move.disabled:hover {
  background: #333;
  color: #bababa;
}

/* Promotion dialog */
#promotion-choice {
  pointer-events: all;
}

#promotion-choice .promotion-shade {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.4);
  z-index: 99;
}

#promotion-choice square {
  background: rgba(20, 85, 30, 0.5);
  backdrop-filter: blur(2px);
  z-index: 200;
}

#promotion-choice square:hover {
  background: rgba(20, 85, 30, 0.85);
}

/* analyse__moves scroll container */
.analyse__moves {
  flex: 1;
  overflow-y: auto;
  min-height: 60px;
}

/* FEN & PGN input area */
.copyables {
  padding: 8px 10px;
  background: #262421;
  border-top: 1px solid #3d3b39;
}

.copyables .pair {
  display: flex;
  flex-direction: column;
  margin-bottom: 8px;
}

.copyables .pair:last-child {
  margin-bottom: 0;
}

.copyables .name {
  color: #9a9a9a;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.copyables input.copyable,
.copyables textarea.copyable {
  background: #1a1917;
  color: #bababa;
  border: 1px solid #3d3b39;
  border-radius: 3px;
  padding: 6px 8px;
  font-family: 'SFMono-Regular', 'Consolas', 'Liberation Mono', 'Menlo', monospace;
  font-size: 12px;
  width: 100%;
  box-sizing: border-box;
  outline: none;
  transition: border-color 0.15s;
}

.copyables input.copyable:focus,
.copyables textarea.copyable:focus {
  border-color: #629924;
}

.copyables input.copyable:invalid {
  border-color: #cc3333;
}

.copyables textarea.copyable {
  resize: vertical;
  min-height: 60px;
  line-height: 1.5;
}

/* Input row with button */
.copyables .input-row {
  display: flex;
  gap: 4px;
}

.copyables .input-row input.copyable {
  flex: 1;
}

.btn-load {
  background: #629924;
  color: #fff;
  border: none;
  border-radius: 3px;
  padding: 4px 10px;
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
  transition: background 0.15s;
}

.btn-load:hover {
  background: #76b02a;
}

.btn-load-pgn {
  margin-top: 6px;
  width: 100%;
  padding: 6px 0;
}

/* Collapsible copyables header */
.copyables__header {
  display: flex;
  align-items: center;
  padding: 6px 10px;
  background: #2b2926;
  border-bottom: 1px solid #3d3b39;
  user-select: none;
}

.copyables__toggle {
  background: none;
  border: none;
  color: #9a9a9a;
  cursor: pointer;
  font-size: 11px;
  padding: 0 6px 0 0;
  line-height: 1;
}

.copyables__title {
  color: #bababa;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  flex: 1;
}

.copyables__actions {
  display: flex;
  gap: 4px;
}

.copyables__gear,
.copyables__hide {
  background: none;
  border: none;
  color: #777;
  cursor: pointer;
  font-size: 14px;
  padding: 0 4px;
  line-height: 1;
  transition: color 0.15s;
}

.copyables__gear:hover,
.copyables__hide:hover {
  color: #ccc;
}

/* Settings panel */
.copyables__settings {
  padding: 8px 10px;
  background: #1e1d1b;
  border-bottom: 1px solid #3d3b39;
}

.setting-row {
  padding: 3px 0;
}

.setting-row label {
  color: #9a9a9a;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
}

.setting-row input[type="checkbox"] {
  accent-color: #629924;
}

/* Body container */
.copyables__body {
  padding: 8px 10px;
}

/* Show button when hidden */
.copyables-toggle {
  border-top: 1px solid #3d3b39;
}

.copyables-show-btn {
  background: none;
  border: none;
  color: #777;
  cursor: pointer;
  font-size: 12px;
  padding: 6px 10px;
  width: 100%;
  text-align: left;
  transition: color 0.15s;
}

.copyables-show-btn:hover {
  color: #bababa;
}

/* Analysis menu (top-right hamburger) */
.analyse__tools {
  width: var(--tools-width);
  min-width: var(--tools-width);
  max-width: var(--tools-width);
  flex-shrink: 0;
  box-sizing: border-box;
  height: 100%;
  max-height: calc(100dvh - 40px);
  background: #262421;
  display: flex;
  flex-direction: column;
  overflow: visible;
  /* Important to show dropdown */
  transform: scale(var(--board-scale-x), var(--board-scale-y));
  transform-origin: center center;
}

.analyse__menu {
  display: flex;
  justify-content: flex-end;
  padding: 8px 8px 0px 0;
  z-index: 1000;
  position: relative;
}

.analyse__menu-btn {
  background: rgba(30, 29, 27, 0.85);
  border: 1px solid #3d3b39;
  color: #bababa;
  cursor: pointer;
  font-size: 16px;
  padding: 3px 8px;
  border-radius: 3px;
  line-height: 1;
  transition: background 0.15s;
}

.analyse__menu-btn {
  background: none;
  border: none;
  color: #bababa;
  font-size: 20px;
  cursor: pointer;
  padding: 0;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background 0.2s;
}

.analyse__menu-btn:hover {
  background: #3d3b39;
}

.analyse__menu-dropdown {
  position: absolute;
  top: 100%;
  right: 8px;
  margin-top: 4px;
  background: #1e1d1b;
  border: 1px solid #3d3b39;
  border-radius: 4px;
  min-width: 200px;
  max-height: 80dvh;
  overflow-y: auto;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  padding: 10px 0;
  z-index: 2000;
}

.menu-section {
  padding: 4px 12px;
}

.menu-section__title {
  color: #777;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
  padding-bottom: 4px;
  border-bottom: 1px solid #333;
}

/* Toast Notifications */
#toast-container {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  background: #333;
  color: white;
  padding: 10px 20px;
  border-radius: 5px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  font-size: 14px;
  animation: toast-fade-in 0.3s ease-out;
  pointer-events: auto;
  border-left: 4px solid #4a9ff5;
}

.toast.success {
  border-left-color: #629924;
}

.toast.error {
  border-left-color: #ff4444;
}

@keyframes toast-fade-in {
  from {
    opacity: 0;
    transform: translateY(20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.toast.fade-out {
  opacity: 0;
  transform: translateY(20px);
  transition: all 0.3s ease-in;
}

/* ======================================================================
   Chessground Base Styles (Inlined for reliability)
   These ensure cg-board, piece, and coords elements are correctly laid out.
   ====================================================================== */

.cg-wrap {
  width: 100%;
  height: 100%;
  position: relative;
  display: block;
}

cg-board {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  line-height: 0;
  background-size: cover;
  cursor: pointer;
}

cg-board square {
  position: absolute;
  top: 0;
  left: 0;
  width: 12.5%;
  height: 12.5%;
  pointer-events: none;
}

cg-board piece {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-size: cover;
  z-index: 2;
  will-change: transform;
  pointer-events: none;
}

cg-board piece.dragging {
  cursor: grabbing;
  z-index: 10;
}

cg-board coords {
  position: absolute;
  display: flex;
  pointer-events: none;
  z-index: 10;
  font-size: 10px;
  font-weight: bold;
  color: rgba(255, 255, 255, 0.7);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

cg-board coords.ranks {
  right: 2px;
  top: 0;
  flex-direction: column-reverse;
  height: 100%;
  width: 12px;
}

cg-board coords.files {
  bottom: 1px;
  left: 0;
  flex-direction: row;
  width: 100%;
  height: 12px;
  text-transform: uppercase;
  text-align: left;
}

cg-board coords coord {
  flex: 1 1 12.5%;
}

cg-board coords.ranks coord {
  display: flex;
  align-items: center;
}

/* Ghost piece during drag */
cg-board piece.ghost {
  opacity: 0.3;
}

/* Anim wrapper */
cg-board piece.anim {
  z-index: 8;
}

/* ======================================================================
   Study Mode Styles
   ====================================================================== */

/* Study sidebar container (puzzle-container layout) */
.puzzle-container {
  display: flex;
  flex: 1;
  height: 100%;
  min-height: 0;
  width: 100%;
  position: relative;
  overflow: hidden;
  background: #161512;
}

.puzzle-sidebar {
  width: 0;
  background: #1e1c1a;
  border-right: none;
  display: flex;
  flex-direction: column;
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow-x: hidden;
  overflow-y: auto;
  flex-shrink: 0;
  z-index: 50;
}

.puzzle-container.sidebar-open .puzzle-sidebar {
  width: 240px;
  border-right: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 0.8rem;
  height: 60px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-header h2 {
  margin: 0;
  font-size: 0.9rem;
  color: #BABABA;
  opacity: 0;
  transition: opacity 0.2s;
}

.puzzle-container.sidebar-open .sidebar-header h2 {
  opacity: 1;
}

.btn-sidebar-toggle {
  box-shadow: 2px 0 5px rgba(0, 0, 0, 0.3);
}

.btn-sidebar-toggle:hover {
  background: #4a9ff5 !important;
}

.puzzle-layout,
.puzzle-main,
.puzzle-analyse-container,
.analyse-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

.set-list,
.puzzle-list {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  width: 100%;
  overflow-y: auto;
}

.set-item,
.puzzle-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0.8rem;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  color: #BABABA;
  font-size: 0.85rem;
}

.set-item:hover,
.puzzle-item:hover {
  background: rgba(255, 255, 255, 0.05);
  color: #fff;
}

.set-item.active,
.puzzle-item.active {
  background: rgba(54, 146, 231, 0.15);
  color: #3692e7;
  border-left: 2px solid #3692e7;
}

/* Modal styles */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10000;
}

.modal-content {
  background: #2b2927;
  padding: 2rem;
  border-radius: 8px;
  width: 100%;
  max-width: 400px;
  color: #bababa;
}

.modal-content input,
.modal-content textarea {
  background: #1e1c1a;
  border: 1px solid #3d3b39;
  color: #fff;
  padding: 0.5rem;
  width: 100%;
  box-sizing: border-box;
}

/* Board container within puzzle/study layout */
.puzzle-board-container {
  position: relative;
  flex: 1 1 auto;
  max-width: calc(100% - 24px);
  max-height: calc(100% - 24px);
  width: auto;
  height: auto;
  aspect-ratio: 1/1;
  min-width: 0;
  min-height: 0;
  flex-shrink: 0;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  border: 8px solid transparent;
  border-radius: 12px;
  margin: 12px;
  box-sizing: border-box;
  overflow: visible;
  /* Reference matched: Allow 1px overflow into border to hide gaps */
  background: #000;
  padding: 0 !important;
  display: block;
}

.analyse .puzzle-board-container {
  /* Inherit general responsive rules but ensure alignment */
  align-self: center;
}

.puzzle-board-container .cg-board-wrap {
  position: absolute !important;
  top: -3px !important;
  left: -3px !important;
  right: -3px !important;
  bottom: -3px !important;
  width: auto !important;
  height: auto !important;
  max-width: none !important;
  max-height: none !important;
  aspect-ratio: auto !important;
  margin: 0 !important;
  padding: 0 !important;
  border-radius: 4px !important;
  /* Reference matched inner curve */
}

.puzzle-board-container .cg-board-wrap .cg-wrap,
.puzzle-board-container .cg-board-wrap .cg-board {
  width: 100% !important;
  height: 100% !important;
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
}

/* 手番インジケーター枠 - 白番 (Reference matched) */
.puzzle-board-container.turn-white {
  border-color: #ffffff;
  box-shadow:
    0 0 0 4px rgba(255, 255, 255, 0.3),
    0 0 30px rgba(255, 255, 255, 0.5),
    0 10px 40px rgba(0, 0, 0, 0.6);
}

/* 手番インジケーター枠 - 黒番 (Reference matched) */
.puzzle-board-container.turn-black {
  border-color: #555555;
  box-shadow:
    0 0 0 4px rgba(255, 255, 255, 0.4),
    0 10px 40px rgba(0, 0, 0, 0.8);
}

.puzzle-board-container.turn-black::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  box-shadow: inset 0 0 30px rgba(255, 255, 255, 0.12);
  pointer-events: none;
  border-radius: 4px;
}

/* Theme applied dynamically via theme.ts */