:root {
  --ink: #20313b;
  --muted: #65747e;
  --paper: #fff;
  --line: #dce6e5;
  --teal: #14747d;
  --teal-dark: #0f5560;
  --green: #148f5b;
  --green-bg: #e7f7ef;
  --red: #c93434;
  --red-bg: #ffecec;
  --sun: #f4c542;
  --grass: #5fae49;
  --grass-dark: #3f8135;
  --shadow: 4px 5px 0 rgba(73, 93, 46, 0.22);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background-color: #8fd4ff;
  background-image:
    linear-gradient(180deg, rgba(255,255,255,0.72) 0 108px, transparent 108px),
    linear-gradient(90deg, rgba(255,255,255,0.18) 1px, transparent 1px),
    linear-gradient(0deg, rgba(255,255,255,0.14) 1px, transparent 1px),
    linear-gradient(180deg, #8fd4ff 0 46%, #72c85b 46% 52%, #6db84b 52% 58%, #9a663b 58% 100%);
  background-size: 100% 100%, 32px 32px, 32px 32px, 100% 100%;
  background-attachment: fixed;
  font-family: "Segoe UI", Arial, sans-serif;
  letter-spacing: 0;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  opacity: 0.38;
  background-image:
    linear-gradient(90deg, transparent 0 48px, rgba(255,255,255,0.55) 48px 96px, transparent 96px 160px),
    linear-gradient(90deg, transparent 0 272px, rgba(255,255,255,0.42) 272px 368px, transparent 368px 520px),
    linear-gradient(90deg, transparent 0 80px, rgba(63,129,53,0.35) 80px 112px, transparent 112px 192px),
    linear-gradient(90deg, transparent 0 224px, rgba(135,146,154,0.42) 224px 256px, transparent 256px 352px);
  background-position: 20px 38px, 190px 104px, 0 calc(100% - 132px), 120px calc(100% - 82px);
  background-size: 560px 64px, 620px 52px, 288px 48px, 416px 44px;
  background-repeat: repeat-x;
  pointer-events: none;
}

button,
input,
select {
  font: inherit;
}

a {
  color: var(--teal-dark);
  font-weight: 850;
  text-decoration: none;
}

.top-band {
  background: rgba(255, 255, 255, 0.9);
  border-bottom: 4px solid var(--grass-dark);
  box-shadow: 0 8px 0 rgba(63, 129, 53, 0.26);
  backdrop-filter: blur(6px);
}

.shell {
  width: min(1180px, calc(100% - 28px));
  margin: 0 auto;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 22px 0 18px;
}

h1 {
  margin: 0;
  color: #24431f;
  text-shadow: 2px 2px 0 #c8ef8c;
  font-size: 2rem;
  line-height: 1.08;
  font-weight: 900;
}

.subtitle {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.45;
}

.nav {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.toolbar {
  background: rgba(237, 247, 245, 0.92);
  border-bottom: 4px solid rgba(138, 90, 53, 0.42);
  backdrop-filter: blur(6px);
}

.toolbar-inner {
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr));
  gap: 12px;
  padding: 14px 0;
}

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

.field label {
  color: var(--teal-dark);
  font-size: 0.86rem;
  font-weight: 900;
}

.input,
.select {
  min-height: 44px;
  width: 100%;
  border: 2px solid #bed4d1;
  border-radius: 4px;
  color: var(--ink);
  background: var(--paper);
  padding: 0 12px;
  outline: none;
}

.input:focus,
.select:focus {
  border-color: #3b82c4;
  box-shadow: 0 0 0 3px rgba(59, 130, 196, 0.16);
}

main {
  padding: 24px 0 108px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(235px, 1fr));
  gap: 12px;
  align-items: stretch;
}

.word-card,
.panel,
.empty-state {
  border: 3px solid #6b8e45;
  border-radius: 4px;
  background:
    linear-gradient(135deg, rgba(255,255,255,0.92), rgba(255,255,255,0.98)),
    repeating-linear-gradient(45deg, #d6efbc 0 14px, #c2e59c 14px 28px);
  box-shadow: var(--shadow);
}

.word-card {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 14px 12px;
}

.word-card.is-hidden {
  display: none;
}

.word {
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 2px;
  color: var(--ink);
  font-size: 1.42rem;
  line-height: 1.2;
  font-weight: 800;
}

.letter {
  min-width: 0.62em;
  padding-top: 6px;
  white-space: pre;
}

.blank {
  width: 2.25rem;
  height: 3.08rem;
  position: relative;
  display: inline-flex;
  justify-content: center;
  flex: 0 0 auto;
}

.blank input {
  width: 2.12rem;
  height: 2.12rem;
  border: 2px solid #bed4d1;
  border-radius: 3px;
  color: var(--ink);
  background: #fbfefd;
  text-align: center;
  font-size: 1.25rem;
  font-weight: 850;
  line-height: 1;
  text-transform: lowercase;
  outline: none;
  box-shadow: inset 0 -3px 0 rgba(32, 49, 59, 0.1);
}

.blank input:focus {
  border-color: #3b82c4;
  box-shadow: 0 0 0 3px rgba(59, 130, 196, 0.16);
}

.blank input[readonly] {
  cursor: default;
}

.blank input.correct {
  border-color: var(--green);
  color: var(--green);
  background: var(--green-bg);
  font-weight: 950;
}

.blank input.wrong {
  border-color: var(--red);
  color: var(--red);
  background: var(--red-bg);
  font-weight: 950;
}

.answer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  min-height: 0.82rem;
  color: var(--green);
  font-size: 0.76rem;
  line-height: 0.82rem;
  font-weight: 900;
  text-align: center;
  visibility: hidden;
}

.show-answers .blank input.wrong + .answer {
  visibility: visible;
}

.word-number {
  width: 2.1rem;
  height: 2.1rem;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 50%;
  color: #fff;
  background: #6f9d43;
  font-size: 0.86rem;
  font-weight: 850;
}

.action-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(12px);
}

.actions {
  min-height: 78px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
}

.status {
  color: var(--muted);
  font-size: 1rem;
  font-weight: 850;
}

.button,
.icon-button {
  min-height: 44px;
  border: 0;
  border-radius: 4px;
  color: #20313b;
  background: var(--sun);
  box-shadow: 3px 4px 0 rgba(73, 93, 46, 0.18);
  font-weight: 950;
  cursor: pointer;
}

.button {
  padding: 0 18px;
}

.button.secondary,
.icon-button.secondary {
  border: 1px solid #cfdedd;
  color: var(--teal-dark);
  background: var(--paper);
}

.button.danger,
.icon-button.danger {
  color: #fff;
  background: var(--red);
}

.button:disabled {
  opacity: 0.45;
  pointer-events: none;
}

.icon-button {
  width: 44px;
  display: inline-grid;
  place-items: center;
  font-size: 1.2rem;
}

.done {
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 170ms ease, transform 170ms ease;
}

.done.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.empty-state {
  display: none;
  margin: 28px 0 0;
  padding: 28px 18px;
  color: #24431f;
  font-size: 1.28rem;
  font-weight: 900;
  text-align: center;
}

.empty-state.is-visible {
  display: block;
}

.teacher-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 16px;
  align-items: start;
}

.panel {
  padding: 16px;
}

.panel h2 {
  margin: 0 0 12px;
  color: #24431f;
  font-size: 1.2rem;
}

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

.set-list {
  display: grid;
  gap: 8px;
}

.set-item {
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 12px;
  border: 2px solid #bed4d1;
  border-radius: 4px;
  color: var(--ink);
  background: #fff;
  text-align: left;
  cursor: pointer;
}

.set-item.is-active {
  border-color: var(--teal);
  background: #e9f5f2;
}

.word-editor {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
  margin-bottom: 14px;
}

.link-editor {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: end;
  margin-bottom: 14px;
  padding: 12px;
  border: 2px solid #bed4d1;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.72);
}

.word-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto auto;
  gap: 8px;
  align-items: center;
  padding: 8px 0;
  border-top: 1px solid rgba(32, 49, 59, 0.12);
}

.login-card {
  width: min(420px, calc(100% - 28px));
  margin: 48px auto;
}

.message {
  min-height: 1.2rem;
  color: var(--red);
  font-weight: 850;
}

.hidden {
  display: none !important;
}

@media (max-width: 820px) {
  .header,
  .actions {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar-inner,
  .teacher-layout,
  .word-editor,
  .link-editor,
  .word-row {
    grid-template-columns: 1fr;
  }

  .grid {
    grid-template-columns: 1fr;
  }

  .word {
    font-size: 1.28rem;
  }
}
