:root {
  --bg-page: #f3f6f0;
  --bg-gradient-a: #f8fbff;
  --bg-gradient-b: #e7f1e9;
  --card: #ffffff;
  --card-border: #c9d6cc;
  --text: #162017;
  --muted: #54655a;
  --accent: #1f7f5a;
  --accent-deep: #146045;
  --danger: #c03131;
  --danger-soft: #ffe9e9;
  --success: #1f8f4d;
  --success-soft: #e8f7ec;
  --shadow: 0 8px 26px rgba(12, 42, 22, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Trebuchet MS", "Segoe UI", "Verdana", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 8% 5%, var(--bg-gradient-a), transparent 40%),
    radial-gradient(circle at 92% 0%, #e6f9f2, transparent 32%),
    linear-gradient(140deg, var(--bg-page), var(--bg-gradient-b));
}

.app-shell {
  max-width: 1160px;
  margin: 0 auto;
  padding: 16px;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.brand h1 {
  margin: 0;
  font-size: clamp(1.35rem, 2vw, 2rem);
  line-height: 1.2;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.admin-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 14px;
  box-shadow: var(--shadow);
}

.stack {
  display: grid;
  gap: 12px;
}

.split {
  display: grid;
  gap: 12px;
}

.field {
  display: grid;
  gap: 6px;
}

.field label {
  font-weight: 700;
}

input,
textarea,
select,
.rich-editor {
  width: 100%;
  border: 1px solid #b7c7bb;
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  color: var(--text);
  background: #fff;
}

textarea {
  resize: vertical;
  min-height: 120px;
}

.rich-editor {
  min-height: 260px;
  background: #fff;
  white-space: pre-wrap;
  line-height: 1.6;
}

.rich-editor:focus {
  outline: 2px solid #8ebea4;
  outline-offset: 1px;
}

.rich-editor p {
  margin: 0 0 0.8em;
}

.rich-editor p:last-child {
  margin-bottom: 0;
}

.editor-main-card {
  min-height: 520px;
}

.editor-canvas {
  position: relative;
}

.editor-marked-word {
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 2px;
  border-radius: 3px;
  padding: 0 1px;
  font-weight: 700;
}

.editor-marked-word-synonym {
  text-decoration-color: #1f7f5a;
  background: #e7f6ed;
  color: #155d3a;
}

.editor-marked-word-antonym {
  text-decoration-color: #b34040;
  background: #fdecec;
  color: #8a2424;
}

.word-dialog-layer {
  position: absolute;
  inset: 0;
  display: grid;
  align-items: start;
  justify-items: center;
  z-index: 20;
  padding: 14px;
}

.word-dialog-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(22, 32, 23, 0.42);
  cursor: default;
}

.word-dialog {
  position: relative;
  width: min(560px, calc(100% - 18px));
  margin-top: 18px;
  border: 1px solid #b9cdbf;
  border-radius: 14px;
  padding: 12px;
  background: #fff;
  box-shadow: var(--shadow);
}

.word-dialog-title {
  margin: 0;
}

button {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 12px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: #f6fffb;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-deep);
}

.btn-secondary {
  background: #eef6f0;
  border-color: #b8cabe;
  color: #224132;
}

.btn-danger {
  background: #fbe2e2;
  border-color: #dbadad;
  color: #842828;
}

.btn-link {
  background: #f6f8fb;
  border-color: #c7d3df;
  color: #1f4863;
}

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

.wysiwyg-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.notice {
  border-radius: 10px;
  padding: 10px 12px;
  font-weight: 600;
}

.notice.info {
  background: #e9f1ff;
  color: #21446e;
}

.notice.error {
  background: #ffeaea;
  color: #7f2424;
}

.notice.success {
  background: #e8f8ee;
  color: #1c6338;
}

.exercise-list {
  display: grid;
  gap: 10px;
}

.exercise-item {
  border: 1px solid #cddacf;
  border-radius: 12px;
  padding: 10px;
  background: #fbfefb;
}

.exercise-item h3 {
  margin: 0 0 6px;
}

.muted {
  color: var(--muted);
}

.token-zone {
  border: 1px dashed #b9c8ba;
  border-radius: 12px;
  padding: 12px;
  background: #f9fcfa;
  min-height: 120px;
  white-space: pre-wrap;
  line-height: 1.75;
}

.token-word {
  display: inline-block;
  border-radius: 6px;
  cursor: pointer;
  padding: 1px 2px;
}

.token-word:hover {
  background: #e7f4ea;
}

.token-word.is-selected {
  background: #ffe5e5;
  border-bottom: 2px solid var(--danger);
}

.token-word.is-current {
  box-shadow: inset 0 0 0 2px #247253;
}

.word-config {
  border: 1px solid #c7d6ca;
  border-radius: 12px;
  padding: 12px;
  background: #f8fcf8;
}

.pill {
  display: inline-block;
  border-radius: 999px;
  padding: 4px 9px;
  background: #ecf2ec;
  border: 1px solid #c7d5c8;
  font-size: 0.85rem;
  margin-right: 6px;
  margin-bottom: 6px;
}

.play-header {
  position: sticky;
  top: 0;
  z-index: 5;
  background: #ffffffeb;
  backdrop-filter: blur(5px);
  border: 1px solid #c8d5ca;
  border-radius: 12px;
  padding: 10px;
  margin-bottom: 10px;
}

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

.play-score {
  font-weight: 800;
  font-size: 1rem;
}

.play-text-area {
  position: relative;
}

.play-text {
  border: 1px solid #c4d2c6;
  border-radius: 12px;
  padding: 14px;
  background: #fffffd;
  min-height: 220px;
  white-space: pre-wrap;
  line-height: 1.8;
  font-size: 1.05rem;
}

.play-word {
  display: inline-block;
  border-radius: 7px;
  padding: 1px 3px;
  cursor: pointer;
  font-weight: 700;
  border: 1px solid transparent;
  vertical-align: middle;
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 2px;
}

.play-word.red {
  background: var(--danger-soft);
  color: #8a2424;
  border-color: #e0b1b1;
}

.play-word.green {
  background: var(--success-soft);
  color: #1f6b3d;
  border-color: #aed5bb;
}

.play-word.active {
  border-color: #155f41;
  box-shadow: 0 0 0 1px #155f41;
}

.play-answer-overlay {
  position: absolute;
  left: var(--overlay-left, 10px);
  top: var(--overlay-top, 10px);
  width: min(360px, calc(100% - 14px));
  z-index: 12;
  pointer-events: none;
}

.inline-answer-box {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 9px 10px;
  border: 1px solid #c4d2c6;
  border-radius: 10px;
  background: #f9fcf9;
  box-shadow: 0 8px 24px rgba(17, 40, 25, 0.16);
  pointer-events: auto;
  position: relative;
}

.inline-answer-box.is-correct {
  border-color: #82c39a;
  background: #e9f7ee;
}

.inline-answer-box.is-wrong {
  border-color: #dfa8a8;
  background: #fff0f0;
}

.inline-answer-title {
  width: 100%;
  font-size: 0.88rem;
  font-weight: 700;
  color: #2d4a39;
  padding-right: 20px;
}

.inline-answer-kind {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: 4px;
  font-size: 1.28rem;
  font-weight: 900;
  line-height: 1.1;
}

.inline-answer-kind.is-synonym {
  color: #167746;
}

.inline-answer-kind.is-antonym {
  color: #b02f2f;
}

.inline-answer-kind-icon {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 900;
  color: #fff;
}

.inline-answer-kind.is-synonym .inline-answer-kind-icon {
  background: #167746;
}

.inline-answer-kind.is-antonym .inline-answer-kind-icon {
  background: #b02f2f;
}

.inline-answer-progress {
  display: inline-block;
  margin-left: 8px;
  font-size: 1.02rem;
  font-weight: 900;
  color: #305644;
}

.inline-answer-box.is-correct .inline-answer-progress {
  color: #1d7a44;
}

.inline-answer-box.is-wrong .inline-answer-progress {
  color: #9a2f2f;
}

.inline-answer-close {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 20px;
  height: 20px;
  padding: 0;
  line-height: 1;
  font-size: 0.96rem;
  border-radius: 999px;
  border: 1px solid #bfd0c2;
  background: #fff;
  color: #355646;
}

.inline-answer-close:hover {
  background: #eef5ef;
  border-color: #9fbeaa;
}

.inline-answer-box label {
  font-size: 0.82rem;
  font-weight: 700;
  color: #2a4c37;
}

.inline-answer-box input {
  width: 100%;
  min-width: 0;
  padding: 7px 9px;
}

.inline-answer-box small {
  font-weight: 700;
  color: #2a4c37;
}

.revealed-inline {
  color: #2a5f41;
  font-weight: 700;
}

.answer-panel {
  position: sticky;
  bottom: 8px;
  margin-top: 12px;
  border: 1px solid #b5cab8;
  border-radius: 12px;
  padding: 12px;
  background: #fff;
  box-shadow: var(--shadow);
}

.answer-panel h3 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.results-table-wrap {
  overflow-x: auto;
}

table {
  border-collapse: collapse;
  width: 100%;
}

th,
td {
  border-bottom: 1px solid #dde5df;
  text-align: left;
  padding: 8px 6px;
  vertical-align: top;
}

th {
  font-size: 0.9rem;
  color: #355343;
}

.result-cards {
  display: grid;
  gap: 10px;
}

.result-card {
  border: 1px solid #c8d5ca;
  border-radius: 12px;
  padding: 10px;
  background: #fcfffc;
}

.result-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.metric {
  background: #f4f8f5;
  border: 1px solid #d2ddd4;
  border-radius: 10px;
  padding: 8px;
}

.metric strong {
  display: block;
  font-size: 0.8rem;
  color: #3a5a49;
}

.metric span {
  font-size: 0.96rem;
  font-weight: 700;
}

.details-list {
  margin-top: 8px;
  padding-left: 16px;
}

.details-list li {
  margin-bottom: 4px;
}

@media (min-width: 900px) {
  .split.admin {
    grid-template-columns: minmax(320px, 360px) 1fr;
    align-items: start;
  }

  .result-cards {
    display: none;
  }
}

@media (max-width: 899px) {
  .results-table-wrap {
    display: none;
  }
}

@media (max-width: 680px) {
  .play-answer-overlay {
    position: fixed;
    left: 10px;
    right: 10px;
    top: var(--overlay-mobile-top, 84px);
    width: auto;
    z-index: 24;
  }

  .play-text {
    padding-top: 18px;
  }
}
