/* constants.css */
:root {
  color-scheme: dark;
  --bg: #141414;
  --surface: #1c1c1c;
  --surface-2: #242424;
  --fg: #ececec;
  --muted: #9a9a9a;
  --border: #2e2e2e;
  --border-strong: #4a4a4a;
  --hover: #2a2a2a;
  --accent: #4c8dff;
  --accent-soft: rgba(76, 141, 255, 0.22);
  --danger: #d4544a;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);

  --dark-gray-bg: var(--bg);
  --light-gray-bg: var(--surface);
  --very-light-gray-bg: var(--surface-2);
  --empty-study-bg: rgba(20, 20, 20, 0.86);
  --gray-hover-bg: var(--hover);
  --blue-hover-bg: var(--accent-soft);
  --blue-selected-bg: var(--accent);
  --modal-gray-bg: var(--surface);
  --delete-red-bg: var(--danger);
  --dark-gray-box-shadow: none;
  --very-dark-gray-border: 1px solid var(--border);
  --dark-gray-border: 1px solid var(--border-strong);
  --light-gray-border: 1px solid var(--border);
  --tree-border: 1px solid var(--border);
  --modal-box-shadow: var(--shadow);
  --dark-gray-gradient: none;
  --light-gray-fg: var(--fg);
  --dark-gray-fg: var(--muted);
  --link-blue-fg: var(--accent);
  --wrong-move-flash: #e85d4c;
  --right-move-flash: #8fbf3f;
  --finish-line-flash: #e2b93b;
  --warning-selected-node-bg: #5c5428;
  --transposition-node-bg: rgba(255, 255, 255, 0.06);
  --transposition-hover-node-bg: rgba(255, 255, 255, 0.12);
  --transposition-selected-node-bg: #3a3a3a;
  --warning-tooltip-bg: #5c5428;
  --sharechess-board-url: none;
  --sharechess-border-url: none;
  --sharechess-border-color: transparent;
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f7f6f3;
    --surface: #ffffff;
    --surface-2: #f0eee9;
    --fg: #1c1c1c;
    --muted: #6d6a64;
    --border: #e4e1da;
    --border-strong: #cfcabe;
    --hover: #f0eee9;
    --accent: #1f6feb;
    --accent-soft: rgba(31, 111, 235, 0.12);
    --danger: #c43830;
    --shadow: 0 12px 32px rgba(40, 36, 28, 0.12);
    --empty-study-bg: rgba(247, 246, 243, 0.9);
    --warning-selected-node-bg: #fff3b0;
    --transposition-node-bg: rgba(0, 0, 0, 0.05);
    --transposition-hover-node-bg: rgba(0, 0, 0, 0.08);
    --transposition-selected-node-bg: #e7e4dc;
  }
}

/* main.css */
body {
  background: var(--bg);
  color: var(--fg);
  font-family: "Segoe UI", system-ui, sans-serif;
  margin: 0;
}

div, img {
  outline: none !important;
}

/** Header */

#title {
  float: left;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.03em;
}

#headerContainer {
  margin: 0 auto;
  padding: 10px 0;
  max-width: 800px;
  width: 90%;
}

#logo {
  position: absolute;
  width: 60px;
}

#header {
  border-bottom: var(--light-gray-border);
  float: right;
  font-size: 14px;
  height: 40px;
  text-align: right;
  width: calc(100% - 80px);
}

/** Mode buttons */

#modeButtons {
  margin: 28px auto 16px;
  text-align: center;
}

#modeButtons .modeButton {
  border: 1px solid var(--border);
  cursor: pointer;
  display: inline-block;
  margin-left: -1px;
  padding: 8px 18px;
  text-align: center;
}

#modeButtons .modeButton.selectedMode {
  background: var(--fg);
  color: var(--bg);
  font-weight: 600;
}

#modeButtons .modeButton:first-child {
  border-radius: 3px 0 0 3px;
}

#modeButtons .modeButton:last-child {
  border-radius: 0 3px 3px 0;
}

/** Picker */

#picker {
  border: var(--very-dark-gray-border);
  font-size: 14px;
  margin: 30px auto 100px auto;
  width: 310px;
}

#picker > div {
  cursor: pointer;
  height: 20px;
  overflow: hidden;
  padding: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#picker > div.metadata:hover {
  background-color: var(--blue-hover-bg);
}

#picker > div.metadata > .metadataName {
  display: inline-block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  width: 265px;
}

#picker > div.metadata.selected {
  background-color: var(--blue-selected-bg);
  color: white;
  font-weight: bold;
  font-weight: 600;
}

#picker > div.metadata > .hoverButton {
  background-size: contain;
  float: right;
  margin: 3px 2px 0 2px;
  opacity: 0.2;
}

#picker > div.metadata > .deleteButton {
  background-image: url(img/x.svg);
  height: 12px;
  width: 12px;
}

#picker > div.metadata:hover > .hoverButton {
  opacity: 0.6;
}

#picker > div.metadata > .hoverButton:hover {
  opacity: 1;
}

#picker > div#addMetadata {
  border-top: var(--very-dark-gray-border);
  color: var(--link-blue-fg);
  opacity: 0.7;
}

#picker > div#addMetadata:hover {
  opacity: 1.0;
}

#picker > div#addMetadata > img {
  height: 14px;
  margin: 2px 5px 0 3px;
}

#picker > div#addMetadata > span {
  vertical-align: top;
}

/** Study mode */

#studyMode {
  text-align: center;
}

#emptyStudy {
  background-color: var(--empty-study-bg);
  height: 47vmin;
  left: 0;
  padding-top: 23vmin;
  position: absolute;
  right: 0;
  z-index: 100;
}

#studyBoard {
  background-size: cover;
  display: inline-block;
  height: 70vmin;
  width: 70vmin;
}

#studyBoard.wrongMove {
  animation-name: wrongMoveFlash;
  animation-duration: 0.6s;
  animation-iteration-count: 1;
}

@keyframes wrongMoveFlash {
  0% {
    box-shadow: 0 0 100px 8px var(--wrong-move-flash);
  }
  100% {
    box-shadow: none;
  }
}

#studyBoard.rightMove {
  animation-name: rightMoveFlash;
  animation-duration: 0.6s;
  animation-iteration-count: 1;
}

@keyframes rightMoveFlash {
  0% {
    box-shadow: 0 0 60px 2px var(--right-move-flash);
  }
  100% {
    box-shadow: none;
  }
}

#studyBoard.finishLine {
  animation-name: finishLineFlash;
  animation-duration: 1.2s;
  animation-iteration-count: 1;
}

@keyframes finishLineFlash {
  0% {
    box-shadow: 0 0 100px 8px var(--finish-line-flash);
  }
  100% {
    box-shadow: none;
  }
}

#studyMessage {
  margin-bottom: 5px;
}

/** Build mode */

#importPgnDialog {
  min-width: 400px;
}

#importPgnDialog > #importPgnTextArea {
  background: none;
  color: var(--light-gray-fg);
  height: 150px;
  margin: 10px 0;
  width: 400px;
}

#importPgnDialog > #importPgnUpload {
  display: block;
  margin-bottom: 10px;
}

#importPgnDialog > #importPgnProgress {
  font-size: 10px;
}

#buildMode {
  text-align: center;
  margin: 0 auto;
}

#buildModeLeft, #buildModeRight {
  display: inline-block;
  vertical-align: top;
  width: 48%;
}

#buildModeLeft {
  text-align: right;
}

#buildModeRight {
  text-align: left;
}

#buildBoard {
  display: inline-block;
  margin: 0 20px 12px 0;
  height: 40vw;
  width: 40vw;
  max-height: 70vh;
  max-width: 70vh;
}
#buildBoard,
#studyBoard,
#evaluateBoard {
  position: relative;
}
#buildBoard svg.board,
#studyBoard svg.board,
#evaluateBoard svg.board {
  display: block;
  height: 100%;
  width: 100%;
}

#colorChooserLabel {
  display: block;
  font-size: 14px;
  margin: 10px 0 0;
}

#colorChooser,
#importPgnOk,
#importPgnUpload {
  font: inherit;
}

#importPgn {
  margin-top: 12px;
}

#importPgnTextArea {
  display: block;
  font: inherit;
  height: 80px;
  margin-bottom: 6px;
  width: 100%;
}

#importStatus,
#status {
  color: var(--fg);
  font-size: 13px;
  margin-top: 6px;
  min-height: 1.2em;
}

#emptyBuild {
  max-width: 300px;
  padding: 20px;
}

#exampleRepertoire {
  color: var(--link-blue-fg);
  cursor: pointer;
  opacity: 0.9;
}

#exampleRepertoire:hover {
  opacity: 1.0;
}

#renameInput {
  border: var(--very-dark-gray-border);
  padding: 5px;
}

#repertoireNameLabel {
  padding: 6px;
}

#renameInput,
#repertoireNameLabel {
  background: none;
  color: var(--light-gray-fg);
  font-family: inherit;
  font-size: 16px;
  margin-bottom: 5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  width: 100%;
}

#buildTreeViewOuter {
  height: calc(40vw - 38px);
}

/** Tree */

.treeViewOuter {
  background-color: var(--light-gray-bg);
  box-shadow: var(--dark-gray-box-shadow);
  box-sizing: border-box;
  display: inline-block;
  max-height: calc(70vh - 38px);
  overflow: scroll;
  padding: 5px;
  resize: both;
  vertical-align: top;
  width: 100%;
}

.treeViewInner {
  /**
   * The segment and row borders are positioned absolutely and must have a
   * relatively-positioned ancestor within the scrolling container.
   */
  position: relative;
}

.treeViewSegment {
  border-left: var(--tree-border);
  padding-left: 15px;
}

.treeViewInner > .treeViewRow:not(:first-child) > .treeViewSegment::before,
.treeViewSegment > .treeViewRow > .treeViewSegment::before {
  border-right: var(--tree-border);
  content: ' ';
  margin-left: -16px;
  margin-top: -11px;
  position: absolute;
  height: 15px;
}

.treeViewInner > .treeViewRow:not(:first-child)::before,
.treeViewSegment > .treeViewRow::before {
  border-top: var(--tree-border);
  content: ' ';
  margin-left: -15px;
  margin-top: 11px;
  position: absolute;
  width: 15px;
}

.treeViewNode {
  --right-ratio: 0;
  cursor: pointer;
  display: inline-block;
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: 14px;
  margin: 0 1px;
  padding: 3px;
}

.treeViewNode-small {
  font-size: 14px;
}

.treeViewNode:hover {
  background-color: var(--blue-hover-bg);
}

.treeViewNode.selectedNode {
  background-color: var(--blue-selected-bg);
  font-weight: 700;
}

.treeViewNode.warningNode {
  animation-name: warningPulsate;
  animation-duration: 3s;
  animation-iteration-count: infinite;
}

.treeViewNode.selectedNode.warningNode {
  background-color: var(--warning-selected-node-bg);
  color: #111;

  animation: none;
}

.treeViewNode.transpositionNode {
  background-color: var(--transposition-node-bg);
}

.treeViewNode.transpositionNode:hover {
  background-color: var(--transposition-hover-node-bg);
}

.treeViewNode.selectedNode.transpositionNode {
  background-color: var(--transposition-selected-node-bg);
}

.treeViewNode.studied {
  background-color: color-mix(in srgb, rgb(155, 199, 0) calc(var(--right-ratio) * 100%), red);
}

@keyframes warningPulsate {
  0% {
    background-color: var(--light-gray-bg);
    color: var(--light-gray-fg);
  }
  25% {
    background-color: #dddd68;
    color: black;
  }
  75% {
    background-color: #dddd68;
    color: black;
  }
  100% {
    background-color: var(--light-gray-bg);
    color: var(--light-gray-fg);
  }
}

.treeButtons {
  margin-top: 5px;
  text-align: center;
  width: 100%;
}

.treeRight {
  -moz-transform: scaleX(-1);
  -o-transform: scaleX(-1);
  -webkit-transform: scaleX(-1);
  transform: scaleX(-1);
  filter: FlipH;
  -ms-filter: "FlipH";
}

.treeTrash {
  padding: 5px 7px !important;
  width: 14px !important;
}

.treeLeft,
.treeRight,
.treeTrash,
.treeExport {
  display: inline-block;
  padding: 5px;
  height: 15px;
  margin: 0;
  width: 18px;
}

/** Evaluate mode */

#evaluateMode {
  margin: 0 auto;
  text-align: center;
}

#evaluateMode .col3:first-child {
  text-align: center;
}

#evaluateMode .col3:nth-child(2) {
  text-align: left;
}

#evaluateMode .col3:last-child {
  text-align: left;
}

.col3 {
  display: inline-block;
  vertical-align: top;
  width: 32%;
}

#emptyEvaluate {
  padding-top: 15px;
  text-align: center;
}

#evaluateBoard {
  background-size: cover;
  display: inline-block;
  height: 70vh;
  width: 70vh;
  max-height: calc(32vw - 100px);
  max-width: calc(32vw - 100px);
}

#insightsPanel {
  margin: 0 30px;
  max-height: 70vh;
}

.insightLabel {
  font-weight: bold;
  margin-bottom: 5px;
}

.insightLabel:not(:first-child) {
  margin-top: 15px;
}

.insight {
  text-align: left;
}

.insight .insightTitle {
  border-bottom: var(--light-gray-border);
  font-size: 12px;
  text-transform: uppercase;
}

.insight .insightValue {
  font-size: 24px;
  font-weight: bold;
}

.insightGray {
  --insight-color: #dfdfdf;
}

.insightYellow {
  --insight-color: #ffd700;
}

.insightGreen {
  --insight-color: rgb(155, 199, 0);
}

.insightRed {
  --insight-color: red;
}

.insightGray,
.insightYellow,
.insightGreen,
.insightRed {
  color: var(--insight-color);
  border-color: var(--insight-color);
}

/** Fixed bottom buttons */

#fixedBottomButtons {
  bottom: 0;
  left: 0;
  position: fixed;
}

/** Footer */

#footer {
  border-top: var(--very-dark-gray-border);
  color: var(--dark-gray-fg);
  font-size: 12px;
  margin: 0 auto;
  max-width: 800px;
  padding: 15px 0 40px 0;
  text-align: center;
  width: 90%;
}

#footer a {
  color: var(--dark-gray-fg);
  margin: 0;
  padding: 0 5px;
  text-decoration: none;
}

/** Other stuff */

.hidden {
  display: none !important;
}

.disabled {
  opacity: 0.3;
}

.selectable {
  cursor: pointer;

  -webkit-transition: background-color 0.2s, opacity 0.2s;
  -moz-transition: background-color 0.2s, opacity 0.2s;
  -o-transition: background-color 0.2s, opacity 0.2s;
  transition: background-color 0.2s, opacity 0.2s;
}

.selectable:hover {
  background-color: var(--gray-hover-bg);
}

@media (prefers-color-scheme: light) {
  .treeLeft,
  .treeRight,
  .treeTrash,
  .treeExport {
    filter: invert(1);
  }
}

#boardStyleLabel,
#pieceStyleLabel {
  margin-right: 12px;
}

.sharechess-board {
  background-color: var(--sharechess-border-color, transparent) !important;
  background-image: var(--sharechess-board-url), var(--sharechess-border-url) !important;
  background-repeat: no-repeat !important;
  background-position: center !important;
  background-size: 100% 100% !important;
}

.cm-chessboard .square.white,
.cm-chessboard .square.black {
  fill: transparent !important;
}

.cm-chessboard .border,
.cm-chessboard .border-inner {
  fill: transparent !important;
  stroke-width: 0 !important;
}


