
/* The study page's own styles, over MAGPIE's analysis.css. */
:root {
  --study-again: #f9e2af;
  --study-close: #f9e2af;
  --study-invalid-row: #f38ba826;
}
:root[data-theme="light"] {
  --study-again: #f2c230;
  --study-close: #9a6700;
  --study-invalid-row: #e8b4bd;
}
.study-prompt {
  margin: 0 0 14px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--raised);
}
#board:focus {
  outline: none;
}
#study-dialog h3 {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}
.study-resume {
  margin-bottom: 20px;
  padding: 14px 16px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--active);
}
/* The saved session's details, laid out as the session panel's, in two
   columns. */
.study-resume dl {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: 16px;
  margin-bottom: 12px;
}
/* The target sets: one row each, label left and size right, in groups by
   word length. */
.study-sets {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
}
.study-set {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  background: transparent;
  text-align: left;
}
.study-set.group-start {
  margin-top: 8px;
}
.study-set-label {
  font-weight: 600;
}
.study-set-description {
  color: var(--muted);
  font-size: 12px;
  font-weight: normal;
}
.study-set[aria-checked="true"] {
  background: var(--active);
  border-color: var(--accent);
}
#study-dialog textarea {
  margin-top: 4px;
}
.study-form-error {
  margin: 8px 0 0;
  color: var(--danger);
}
.study-dialog-progress {
  display: grid;
  gap: 6px;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.study-dialog-progress p {
  margin: 0;
  color: var(--muted);
}
.study-dialog-progress progress {
  width: 100%;
  height: 6px;
  accent-color: var(--accent);
}
#study-new-session {
  width: 100%;
}
/* Submit sits at the right, so the rack buttons stay put when it hides. */
#move-entry #play-move {
  order: 1;
  margin-left: auto;
}
#study-next kbd {
  font: inherit;
  opacity: 0.7;
}
.study-finished #board-viewport,
.study-finished #rack-tiles,
.study-finished .rack-actions {
  display: none;
}
.study-panel {
  grid-column: 2;
  grid-row: 1;
  margin: 0;
}
.study-panel h2,
.study-stats h2,
.study-info h2 {
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 600;
}
.study-panel h3 {
  margin: 16px 0 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}
.study-panel h3:empty {
  display: none;
}
.study-panel .empty {
  padding: 40px 12px;
}
#study-moves {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}
#study-moves th {
  text-align: left;
  color: var(--muted);
  font-weight: 500;
  padding: 4px 8px;
  border-bottom: 1px solid var(--line);
}
#study-moves th:first-child,
#study-moves td.study-score {
  width: 3em;
  text-align: right;
}
#study-moves td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--row-line);
}
#study-moves .study-coordinate {
  width: 3.5em;
  padding-left: 14px;
  color: var(--muted);
}
#study-moves .study-word {
  width: 100%;
  text-align: left;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.04em;
}
#study-moves tr.selected {
  background: var(--selected-row);
}
#study-moves tr.selected > td:first-child {
  box-shadow: inset 3px 0 var(--accent);
}
/* Invalid plays (phonies) sit below the valid ones, dimmed unless last. */
#study-moves tr.invalid:not(.selected) td {
  color: var(--muted);
}
#study-moves tr.invalid td.study-score {
  text-decoration: line-through;
}
#study-moves tr.invalid.selected {
  background: var(--study-invalid-row);
}
#study-moves tr.invalid.selected td {
  color: var(--text);
}
#study-moves tr.invalid.selected > td:first-child {
  box-shadow: inset 3px 0 var(--danger);
}
#study-moves tr.correct {
  background: var(--played-row);
}
#study-moves tr.correct > td:first-child {
  box-shadow: inset 3px 0 var(--positive);
}
.study-note {
  font-family: system-ui, sans-serif;
  letter-spacing: 0;
  color: var(--muted);
  font-size: 12px;
}
tr.correct .study-note {
  color: var(--positive);
}
/* "close!" and "(invalid)" sit two spaces after the play's words. */
.study-note-close,
.study-note-invalid {
  margin-left: 0.55em;
}
tr.close .study-note {
  color: var(--study-close);
}
#study-review-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.study-scenario {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--row-line);
}
.study-scenario-label {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.06em;
}
/* A two-position switch: ✓ reviewed (off) or ↻ re-review (on). */
.study-switch {
  position: relative;
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  flex: none;
  width: 64px;
  height: 28px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--raised);
  cursor: pointer;
}
.study-switch::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 28px;
  height: 22px;
  border-radius: 11px;
  background: var(--positive);
  transition: transform 0.15s ease, background-color 0.15s ease;
}
.study-switch[aria-checked="true"]::before {
  transform: translateX(30px);
  background: var(--study-again);
}
.study-switch-option {
  position: relative;
  display: grid;
  place-items: center;
  font-size: 14px;
  line-height: 1;
  color: var(--muted);
}
.study-switch[aria-checked="false"] .study-switch-done,
.study-switch[aria-checked="true"] .study-switch-again {
  color: #1e1e2e;
  font-weight: 700;
}
.study-nav {
  display: flex;
  gap: 8px;
}
.study-nav:has(button:not([hidden])) {
  margin-top: 14px;
}
.study-nav .primary {
  margin-top: 0;
}
#study-next {
  flex: 1;
}
/* An earlier exercise on show: where it is, and the way back. */
.study-looking-back {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 14px;
  padding: 8px 8px 8px 12px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--active);
}
.study-looking-back p {
  margin: 0;
}
.study-info dl,
.study-resume dl {
  display: grid;
  gap: 2px;
  margin: 0;
}
.study-info dt,
.study-resume dt {
  color: var(--muted);
  font-size: 12px;
  margin-top: 8px;
}
.study-info dd,
.study-resume dd {
  margin: 0;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}
.study-background {
  display: grid;
  gap: 6px;
  margin-top: 14px;
}
.study-background p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}
.study-background progress {
  width: 100%;
  height: 6px;
  accent-color: var(--accent);
}
.brand-rail .study-info {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
.study-progress {
  display: grid;
  gap: 8px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.study-progress p {
  margin: 0;
  color: var(--muted);
}
.study-progress progress {
  width: 100%;
  height: 8px;
  accent-color: var(--accent);
}
.study-progress .primary {
  margin-top: 0;
  justify-self: start;
}
.study-stats {
  padding: 8px 0 4px;
}
.study-stat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 0;
}
.study-stat {
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--raised);
}
.study-stat dt {
  color: var(--muted);
}
.study-stat dd {
  margin: 6px 0 0;
  font-size: 26px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.study-stat small {
  font-size: 14px;
  font-weight: 400;
  color: var(--muted);
}
@media (max-width: 1000px) {
  .study-panel {
    grid-column: 1;
    grid-row: auto;
  }
}
@media (min-width: 1360px) {
  .study-panel {
    grid-column: 3;
    grid-row: 1;
  }
}

/* The header. Wide: the title, credit and settings stacked in the left
   rail. Medium: in a row, settings at the right. Small: a menu button and
   the logo at the left, opening a menu of the three, and the session's
   summary at the right. */
.brand-subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}
.brand-subtitle a {
  color: var(--accent);
}
.app-menu {
  display: contents;
}
.menu-toggle,
.study-summary {
  display: none;
}
@media (min-width: 1360px) {
  .brand-subtitle,
  .settings-button {
    grid-column: 1 / -1;
  }
  .settings-button {
    margin-top: 6px;
    width: 100%;
    text-align: left;
  }
}
@media (min-width: 1001px) and (max-width: 1359px) {
  .brand {
    flex: 1;
  }
  .settings-button {
    margin-left: auto;
  }
}
@media (max-width: 1000px) {
  .app-header {
    flex-wrap: nowrap;
    gap: 12px;
    padding-block: 10px;
  }
  .brand {
    position: relative;
    flex: none;
    gap: 8px;
  }
  .menu-toggle {
    display: block;
    padding: 5px;
  }
  .app-menu {
    display: none;
  }
  .app-menu.open {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    z-index: 30;
    display: grid;
    gap: 6px;
    min-width: 220px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: 0 6px 20px #0004;
  }
  .app-menu h1 {
    font-size: 19px;
  }
  .app-menu .settings-button {
    margin-top: 8px;
    text-align: left;
  }
  .study-summary {
    display: block;
    flex: 1;
    min-width: 0;
    margin: 0;
    overflow: hidden;
    color: var(--muted);
    font-size: 13px;
    text-align: right;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

/* Medium and small: the session's details in two columns. */
@media (max-width: 1359px) {
  .study-info dl {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 16px;
  }
}
/* Medium: the session's panel under the plays, beside the board; small:
   under the plays, below the board. */
@media (min-width: 1001px) and (max-width: 1359px) {
  #game-view {
    grid-template-rows: auto 1fr;
  }
  /* As specific as analysis.css's rule that keeps it to the first row. */
  body:not(.playing) #game-view .position {
    grid-row: 1 / span 2;
  }
  .study-info-panel {
    grid-column: 2;
    grid-row: 2;
  }
}
@media (max-width: 1000px) {
  .study-info-panel {
    grid-column: 1;
  }
}

/* A solved exercise's answer: green, as draft tiles are amber. */
.square.played.preview.solved {
  background: var(--tentative-green);
  box-shadow: inset 0 0 0 1.5px var(--tentative-green-edge), 0 1px 1px #0004;
}

/* The solved modal (small layout) holds the plays panel as is, with a
   close button at its top right. */
.study-solved {
  position: fixed;
  width: min(560px, calc(100% - 24px));
  max-height: calc(100dvh - 24px);
  padding: 0;
  border: 0;
  background: transparent;
  overflow: auto;
}
.study-solved .study-panel {
  margin: 0;
}
.study-solved .study-prompt {
  display: none;
}
.study-solved-close {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 1;
  padding: 2px 10px;
  font-size: 18px;
  line-height: 1.4;
}

#study-settings {
  min-width: min(360px, 90vw);
}
.settings-rows {
  display: grid;
  gap: 8px;
}
.settings-rows select {
  padding: 6px;
  margin-bottom: 8px;
}
.settings-rows .check {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* With every tile on the board, a reminder sits where the rack was, and
   flashes when the play is submitted. It lets drops through to the rack. */
.rack-area {
  position: relative;
}
.rack-reminder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 0 12px;
  color: var(--muted);
  font-size: 17px;
  text-align: center;
  pointer-events: none;
}
.rack-reminder[hidden] {
  display: none;
}
/* The flash: red, and briefly larger. */
.rack-reminder.flash {
  animation: rack-reminder-flash 0.9s ease;
}
@keyframes rack-reminder-flash {
  0%,
  50% {
    color: var(--danger);
    transform: scale(1.15);
  }
  25%,
  75% {
    color: var(--text);
    transform: scale(1.08);
  }
  100% {
    transform: scale(1);
  }
}
@media (prefers-reduced-motion: reduce) {
  .rack-reminder.flash {
    animation: none;
    color: var(--danger);
  }
}

/* Toasts (small layout): over the header, at the top of the view. A new
   one fades in moving down; the one it replaces fades out moving up,
   behind it. */
.toasts {
  position: fixed;
  top: 8px;
  left: 8px;
  right: 8px;
  z-index: 40;
  pointer-events: none;
}
.toast {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 560px;
  margin: 0 auto;
  padding: 6px 6px 6px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 6px 20px #0005;
  font-size: 13px;
  pointer-events: auto;
  animation: toast-enter 0.25s ease-out;
}
.toast.leaving {
  z-index: -1;
  pointer-events: none;
  animation: toast-leave 0.5s ease-in forwards;
}
.toast-text {
  flex: 1;
  min-width: 0;
}
.toast-verdict {
  font-weight: 600;
}
.toast-verdict-close {
  color: var(--study-close);
}
.toast-verdict-invalid {
  color: var(--danger);
}
.toast-dismiss {
  flex: none;
  padding: 2px 9px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.3;
}
.toast-dismiss:hover {
  background: var(--hover);
  color: var(--text);
}
@keyframes toast-enter {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
}
@keyframes toast-leave {
  to {
    opacity: 0;
    transform: translateY(-12px);
  }
}

/* Hints. The hint row heads the play list, in the muted color; tiles a
   Tiles hint rules out are dark, on the rack and on the board; the Hint
   button sits just left of Submit. */
#study-moves tr.hint {
  background: color-mix(in srgb, var(--surface) 86%, black);
}
:root[data-theme="light"] #study-moves tr.hint {
  background: color-mix(in srgb, var(--surface) 92%, black);
}
#study-moves tr.hint td {
  color: var(--muted);
}
#study-moves tr.hint > td:first-child {
  box-shadow: inset 3px 0 var(--line);
}
.study-note-hint {
  margin-left: 0.55em;
  color: var(--accent);
}
.rack-tile.hint-unused,
#board .square.played.hint-unused {
  filter: brightness(0.55) saturate(0.6);
}
:root[data-theme="light"] .rack-tile.hint-unused,
:root[data-theme="light"] #board .square.played.hint-unused {
  filter: brightness(0.75) saturate(0.6);
}
.study-hints-used {
  margin: 10px 0 0;
  color: var(--muted);
}
.study-hint-used[hidden] {
  display: none;
}
#move-entry #study-hint-open {
  order: 1;
  margin-left: auto;
}
/* As far from Submit as the rack buttons are from each other (the row's
   gap). */
#move-entry #study-hint-open + #play-move {
  order: 2;
  margin-left: 0;
}
#study-hint {
  width: min(400px, calc(100% - 30px));
}
/* A Location hint: the answer's row or column label in bold blue, the
   others faded toward the background (darker in the dark theme, lighter
   in the light one). */
#board.hint-location .coordinate:not(.hint-line) {
  opacity: 0.84;
}
#board .coordinate.hint-line {
  color: var(--accent);
  font-weight: 700;
}

/* Light theme: lighter fills for the primary buttons (Submit, Next
   exercise...) and the switch's ✓ knob, with dark text (7.8:1 and 7.3:1)
   and an edge in a darker color, as on the ↻ knob. */
:root[data-theme="light"] .primary {
  background: #99c2e3;
  border-color: #3e5e73;
  color: #1e2a33;
}
:root[data-theme="light"] .study-switch[aria-checked="false"]::before {
  background: #92b78c;
  box-shadow: inset 0 0 0 1px #486548;
}
:root[data-theme="light"] .study-switch[aria-checked="true"]::before {
  /* 3.4:1 against the track. */
  box-shadow: inset 0 0 0 1px #8a6d00;
}

/* Light theme: brighter marks at the left of the play list's selected,
   invalid and correct rows (the theme's blue, red and green, lighter and
   more saturated). */
:root[data-theme="light"] #study-moves tr.selected > td:first-child {
  box-shadow: inset 3px 0 #5fa0cb;
}
:root[data-theme="light"] #study-moves tr.invalid.selected > td:first-child {
  box-shadow: inset 3px 0 #dd7b8c;
}
:root[data-theme="light"] #study-moves tr.correct > td:first-child {
  box-shadow: inset 3px 0 #6abc6a;
}
/* Half the space under the session's heading. */
.study-info h2 {
  margin-bottom: 2px;
}
