/* Derived from apps/chess-pocket/public/css/style.css.
 * Adapted for chess-pocket-train and the Atlas generated frontend modules.
 */
:root {
  color-scheme: dark;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: #1a1a1a;
  color: #fff;
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow-x: hidden;
  background: #1a1a1a;
  overscroll-behavior: none;
}

button,
select,
input,
textarea { font: inherit; }

button { min-height: 44px; touch-action: manipulation; }

[hidden] { display: none !important; }

.train-shell {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(320px, 70vmin) minmax(180px, 1fr);
  align-items: center;
  gap: 20px;
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  padding: max(20px, env(safe-area-inset-top)) 20px max(20px, env(safe-area-inset-bottom));
}

.train-header {
  justify-self: end;
  max-width: 280px;
  overflow: visible;
  text-align: right;
}

.train-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  gap: 8px;
}

h1 {
  margin: 0;
  color: #f0d9b5;
  font-size: 3rem;
  line-height: 1.1;
  letter-spacing: 0;
  text-shadow: 2px 2px 0 #000;
}

.train-title-button {
  appearance: none;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  line-height: inherit;
  text-align: inherit;
  text-shadow: inherit;
  cursor: pointer;
}

.train-title-button:active { transform: scale(0.985); }

.train-title-button:focus-visible {
  border-radius: 4px;
  outline: 2px solid currentColor;
  outline-offset: 3px;
}

.train-kicker {
  margin: 10px 0 0;
  color: #9ea7b3;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
}

.status-evaluation-row {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  min-width: 0;
  min-height: 28px;
  margin-top: 12px;
  overflow: hidden;
}

#status {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 1.5em;
  margin: 0;
  color: #ccc;
  font-size: 1.05rem;
  font-weight: 700;
  overflow: hidden;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.evaluation-badge {
  flex: 0 0 auto;
  box-sizing: border-box;
  min-width: 54px;
  min-height: 24px;
  padding: 2px 7px;
  border: 1px solid #d9b86c;
  border-radius: 6px;
  background: #343126;
  color: #ffd166;
  font-size: 0.82rem;
  font-weight: 800;
  line-height: 1.1;
  white-space: nowrap;
  cursor: pointer;
}

.evaluation-badge.is-hidden {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.evaluation-badge:disabled {
  cursor: default;
}

.evaluation-badge:hover,
.evaluation-badge:focus-visible {
  background: #494331;
  outline: 2px solid #ffd166;
  outline-offset: 2px;
}

.board-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
}

#chessboard {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: min(70vmin, 720px);
  height: min(70vmin, 720px);
  border: 8px solid #555;
  background: #000;
  box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
  user-select: none;
  touch-action: none;
  transition: transform 0.35s ease;
}

#chessboard.flipped { transform: rotate(180deg); }
#chessboard.flipped .piece { transform: rotate(180deg); }

.square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  aspect-ratio: 1;
  cursor: pointer;
}

.square.white { background: #f0d9b5; }
.square.black { background: #b58863; }

.piece {
  width: 85%;
  height: 85%;
  object-fit: contain;
  pointer-events: none;
  transition: transform 0.35s ease;
}

.square.last-move { box-shadow: inset 0 0 0 4px #ffd700; }
.square.selected { box-shadow: inset 0 0 0 4px #00aaff; }
.square.target-move { box-shadow: inset 0 0 0 4px #33cc33; }
.square.target-capture { box-shadow: inset 0 0 0 4px #ff4444; }

.board-toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  margin-top: 14px;
  color: #ccc;
}

#ai-provider {
  min-height: 42px;
  padding: 7px 10px;
  border: 1px solid #777;
  border-radius: 6px;
  background: #333;
  color: #fff;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 46px;
  padding: 0;
  border: 1px solid #777;
  border-radius: 6px;
  background: #333;
  color: #fff;
  cursor: pointer;
}

.train-actions {
  display: grid;
  gap: 10px;
  justify-self: start;
  width: min(260px, 100%);
}

.train-action {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px 14px;
  border: 1px solid #777;
  border-radius: 6px;
  background: #333;
  color: #fff;
  text-align: left;
  cursor: pointer;
}

.imported-file-action {
  grid-template-columns: auto minmax(0, 1fr);
  border-color: #6f879f;
  background: #2a3036;
}

.imported-file-action-copy {
  display: grid;
  min-width: 0;
}

.imported-file-action-copy strong,
.imported-file-action-copy small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.imported-file-action-copy small {
  color: #b7c5d4;
  font-size: 0.68rem;
}

.train-action:hover,
.icon-button:hover { background: #444; }

.train-action:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

.train-action:disabled:hover { background: #333; }

.train-action:active,
.icon-button:active { transform: scale(0.98); }

.action-icon { width: 24px; text-align: center; font-size: 1.15rem; }

.phase-notice {
  min-height: 1.4em;
  margin: 2px 0 0;
  color: #aeb7c2;
  font-size: 0.88rem;
  line-height: 1.4;
}

.fen-editor-panel {
  display: grid;
  gap: 8px;
  justify-self: start;
  width: min(310px, 100%);
  padding: 8px;
  border: 1px solid #555;
  border-radius: 6px;
  background: #242424;
}

.piece-palette {
  display: grid;
  grid-template-columns: repeat(6, minmax(38px, 1fr));
  gap: 4px;
}

.piece-palette-button {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 42px;
  padding: 2px;
  border: 1px solid #666;
  border-radius: 5px;
  background: #333;
  cursor: pointer;
}

.piece-palette-button img {
  width: 34px;
  height: 34px;
  object-fit: contain;
  pointer-events: none;
}

.piece-palette-button.is-selected,
.fen-small-button.is-selected,
.fen-segmented button.is-selected {
  outline: 3px solid #ffd166;
  outline-offset: -3px;
}

.piece-palette-button.is-selected::after,
.fen-small-button.is-selected::after {
  content: "✓";
  position: absolute;
  top: 0;
  right: 3px;
  color: #ffd166;
  font-size: 0.72rem;
  font-weight: 900;
}

.fen-action-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
}

.fen-small-button,
.fen-segmented button {
  position: relative;
  min-width: 0;
  min-height: 38px;
  padding: 5px 6px;
  border: 1px solid #666;
  border-radius: 5px;
  background: #333;
  color: #fff;
  cursor: pointer;
  font-size: 0.78rem;
}

.fen-option-row {
  display: grid;
  grid-template-columns: auto 1fr auto minmax(74px, auto);
  align-items: center;
  gap: 6px;
  color: #ccc;
  font-size: 0.78rem;
}

.fen-segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
}

#fen-en-passant {
  min-height: 38px;
  padding: 4px;
  border: 1px solid #666;
  border-radius: 5px;
  background: #333;
  color: #fff;
}

.fen-castling-trigger {
  min-height: 36px;
  padding: 5px 8px;
  border: 1px solid #666;
  border-radius: 5px;
  background: #303030;
  color: #ddd;
  cursor: pointer;
  font-size: 0.76rem;
  text-align: left;
}

.fen-primary-action { border-color: #66bb6a; }
#fen-menu { border-color: #a88b57; }

.fen-output {
  display: block;
  min-height: 1.4em;
  padding: 5px 7px;
  overflow-wrap: anywhere;
  border-radius: 4px;
  background: #151515;
  color: #d9e2ee;
  font: 0.72rem/1.35 ui-monospace, SFMono-Regular, Consolas, monospace;
}

.fen-output:empty { display: none; }

.fen-editor-message {
  min-height: 1.25em;
  margin: 0;
  color: #bbb;
  font-size: 0.76rem;
  line-height: 1.3;
}

.fen-editor-message[data-tone="error"] { color: #ff8d87; }
.fen-editor-message[data-tone="success"] { color: #8de3a9; }

.save-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
  overflow: hidden;
  background: rgba(0, 0, 0, 0.78);
}

.save-modal-panel {
  display: grid;
  gap: 9px;
  width: min(430px, 100%);
  max-height: min(88dvh, 640px);
  padding: 12px;
  overflow-y: auto;
  border: 1px solid #777;
  border-radius: 6px;
  background: #242424;
  box-shadow: 0 16px 38px rgba(0, 0, 0, 0.5);
}

.castling-modal-panel {
  width: min(360px, 100%);
  max-height: min(82dvh, 420px);
}

.fen-import-panel {
  width: min(430px, 100%);
  max-height: min(86dvh, 560px);
}

.home-confirmation-panel {
  width: min(390px, 100%);
  max-height: min(72dvh, 300px);
}

.home-confirmation-message {
  margin: 0;
  color: #d5d9df;
  font-size: 0.86rem;
  line-height: 1.4;
}

#fen-import-text {
  min-height: 76px;
  max-height: 112px;
  resize: vertical;
}

.fen-import-filename {
  min-height: 1.2em;
  margin: 0;
  overflow: hidden;
  color: #b9c0c8;
  font-size: 0.76rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fen-import-actions {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr);
  gap: 7px;
}

.fen-import-actions button {
  min-height: 42px;
  padding: 6px 9px;
  border: 1px solid #777;
  border-radius: 5px;
  background: #333;
  color: #fff;
}

#fen-import-submit { border-color: #66bb6a; }

.castling-help {
  margin: 0;
  color: #b9c0c8;
  font-size: 0.78rem;
  line-height: 1.35;
}

.castling-human-groups {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.castling-human-group {
  min-width: 0;
  margin: 0;
  padding: 7px;
  border: 1px solid #5d6269;
  border-radius: 5px;
}

.castling-human-group legend {
  padding: 0 4px;
  color: #f0d9b5;
  font-size: 0.8rem;
  font-weight: 700;
}

.castling-human-option {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  color: #fff;
  font-size: 0.78rem;
}

.castling-human-option input:disabled + span { color: #777; }

#fen-castling-done { width: 100%; }

.save-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.save-modal-header h2 {
  margin: 0;
  color: #f0d9b5;
  font-size: 1.15rem;
  letter-spacing: 0;
}

.save-modal-close {
  display: grid;
  place-items: center;
  width: 40px;
  min-height: 40px;
  padding: 0;
  border: 1px solid #666;
  border-radius: 5px;
  background: #333;
  color: #fff;
  font-size: 1.35rem;
}

.save-field {
  display: grid;
  gap: 4px;
  color: #ccc;
  font-size: 0.78rem;
}

.save-field input,
.save-field textarea,
.save-field select {
  width: 100%;
  min-height: 40px;
  padding: 7px 9px;
  border: 1px solid #666;
  border-radius: 5px;
  background: #181818;
  color: #fff;
}

.save-field textarea {
  min-height: 58px;
  resize: vertical;
}

.save-themes-fieldset {
  min-width: 0;
  margin: 0;
  padding: 7px;
  border: 1px solid #555;
  border-radius: 5px;
}

.save-themes-fieldset legend,
.save-fen-preview > span {
  color: #ccc;
  font-size: 0.78rem;
}

.save-theme-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 5px;
}

.save-theme-option {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  min-height: 38px;
  padding: 5px 6px;
  border: 1px solid #666;
  border-radius: 5px;
  background: #303030;
  color: #fff;
  font-size: 0.76rem;
}

.save-theme-option span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.save-fen-preview {
  display: grid;
  gap: 3px;
}

.save-fen-preview output {
  max-height: 3.2em;
  padding: 5px 7px;
  overflow: auto;
  border-radius: 4px;
  background: #151515;
  color: #d9e2ee;
  font: 0.7rem/1.3 ui-monospace, SFMono-Regular, Consolas, monospace;
}

.save-inline-status,
.save-modal-error {
  min-height: 1.2em;
  margin: 0;
  color: #bbb;
  font-size: 0.76rem;
}

.save-modal-error { color: #ff8d87; }

.save-modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.save-modal-actions button {
  min-height: 42px;
  border: 1px solid #777;
  border-radius: 5px;
  background: #333;
  color: #fff;
}

.evaluation-modal-panel { max-width: 390px; }

.evaluation-context {
  margin: 0;
  color: #aeb7c2;
  font-size: 0.82rem;
  line-height: 1.35;
}

.evaluation-details {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(90px, auto);
  gap: 8px 14px;
  margin: 0;
}

.evaluation-details dt {
  min-width: 0;
  color: #bcc4ce;
}

.evaluation-details dd {
  min-width: 0;
  margin: 0;
  color: #fff;
  font-weight: 700;
  overflow-wrap: anywhere;
  text-align: right;
}

#save-position-submit { border-color: #66bb6a; }

.positions-library-panel {
  width: min(520px, 100%);
  max-height: min(90dvh, 720px);
}

.epd-collection-panel { max-height: min(90dvh, 720px); }

.epd-collection-filename {
  max-width: 330px;
  margin: 3px 0 0;
  overflow: hidden;
  color: #aeb7c2;
  font-size: 0.72rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.epd-collection-list {
  max-height: min(48dvh, 440px);
  padding-right: 2px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.epd-position-id,
.epd-source-badge {
  grid-column: 1;
  margin: 0;
  overflow-wrap: anywhere;
  color: #9fb6d0;
  font-size: 0.7rem;
}

.epd-position-card.is-selected {
  border-color: #8eb4d6;
  box-shadow: inset 3px 0 0 #8eb4d6;
}

.imported-file-footer {
  display: flex;
  justify-content: flex-end;
}

.imported-file-footer button {
  min-height: 36px;
  padding: 6px 9px;
  border: 1px solid #765b5b;
  border-radius: 5px;
  background: #302828;
  color: #f1c2c2;
}

.epd-source-badge {
  width: fit-content;
  padding: 2px 5px;
  border: 1px solid #596a7b;
  border-radius: 4px;
  color: #c7d9eb;
}

.epd-errors {
  padding: 6px 8px;
  border: 1px solid #6f5656;
  border-radius: 5px;
  color: #ffb0aa;
  font-size: 0.74rem;
}

.epd-errors summary { cursor: pointer; }

.epd-errors p {
  margin: 5px 0 0;
  overflow-wrap: anywhere;
}

.positions-library-filters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.positions-library-list {
  display: grid;
  gap: 7px;
  min-height: 80px;
}

.positions-library-empty {
  margin: 12px 0;
  color: #bbb;
  text-align: center;
  font-size: 0.84rem;
}

.position-library-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 9px;
  align-items: center;
  padding: 9px;
  border: 1px solid #5f6670;
  border-radius: 6px;
  background: #1b1d20;
}

.position-library-card h3 {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
  color: #f0d9b5;
  font-size: 0.94rem;
  letter-spacing: 0;
}

.position-library-comment,
.position-library-meta,
.position-library-details {
  grid-column: 1;
  margin: 0;
  overflow-wrap: anywhere;
}

.position-library-comment {
  color: #e1e5ea;
  font-size: 0.8rem;
}

.position-library-meta,
.position-library-details {
  color: #aeb7c2;
  font-size: 0.72rem;
}

.position-library-open {
  grid-column: 2;
  grid-row: 1 / span 4;
  min-width: 82px;
  min-height: 44px;
  padding: 6px 9px;
  border: 1px solid #66bb6a;
  border-radius: 5px;
  background: #303630;
  color: #fff;
}

@media (max-aspect-ratio: 1/1) {
  .train-shell {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    gap: 12px;
    min-height: 100dvh;
    padding: max(10px, env(safe-area-inset-top)) 0 max(28px, env(safe-area-inset-bottom));
  }

  .train-header {
    flex: 0 0 auto;
    width: 100%;
    max-width: none;
    padding: 0 14px;
    text-align: center;
  }

  .train-title-row { justify-content: center; align-items: center; }
  h1 { font-size: 2.35rem; }
  .train-kicker { margin-top: 4px; }
  .status-evaluation-row { justify-content: flex-end; margin-top: 6px; }

  #chessboard {
    width: 94vw;
    height: 94vw;
    border-width: 4px;
  }

  .board-toolbar { margin-top: 9px; }

  .train-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: calc(100% - 20px);
    max-width: 620px;
  }

  .train-action {
    justify-content: center;
    min-height: 50px;
    padding: 8px 10px;
    line-height: 1.15;
    text-align: center;
  }

  .phase-notice {
    width: calc(100% - 24px);
    text-align: center;
  }

  .fen-editor-panel {
    width: calc(100% - 20px);
    max-width: 620px;
    padding: 6px;
    gap: 6px;
  }

  .piece-palette-button { min-height: 40px; }
  .piece-palette-button img { width: 32px; height: 32px; }

  .fen-action-row {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .fen-option-row {
    grid-template-columns: auto minmax(120px, 1fr) auto minmax(78px, auto);
  }
}

@media (max-width: 380px) {
  h1 { font-size: 2rem; }
  .train-action { font-size: 0.86rem; }
  .fen-small-button { font-size: 0.7rem; }
  .fen-option-row { font-size: 0.7rem; gap: 4px; }
  .save-modal-panel { gap: 7px; padding: 9px; }
  .save-theme-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .positions-library-filters { gap: 5px; }
  .position-library-open { min-width: 74px; }
  .fen-import-actions { grid-template-columns: 1fr 1fr; }
  #fen-import-submit { grid-column: 1 / -1; }
}
