:root {
  color-scheme: light;
  --bg: #f6f7f8;
  --surface: #ffffff;
  --surface-strong: #eef2f4;
  --ink: #161718;
  --muted: #667077;
  --line: #d9e0e5;
  --line-strong: #aebbc5;
  --green: #2f745d;
  --blue: #2f5f8f;
  --red: #b84a42;
  --gold: #be802f;
  --shadow: 0 18px 48px rgba(23, 31, 38, 0.09);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

html {
  min-height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(47, 116, 93, 0.08), rgba(47, 95, 143, 0) 260px),
    var(--bg);
  color: var(--ink);
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
dialog:focus-visible,
.flashcard:focus-visible {
  outline: 3px solid rgba(47, 95, 143, 0.25);
  outline-offset: 2px;
}

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

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.topbar h1,
.section-head h2,
.panel-head h2 {
  margin: 2px 0 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: 2.1rem;
  line-height: 1.05;
}

.eyebrow {
  margin: 0;
  color: var(--green);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.stats {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: end;
}

.stats article {
  min-width: 92px;
  display: grid;
  gap: 2px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
}

.stats span {
  color: var(--muted);
  font-size: 0.78rem;
}

.stats strong {
  font-size: 1.45rem;
  line-height: 1;
}

.view-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.tab-button,
.quick-row button,
.deck-toggle button,
.card-actions button,
.utility-row button,
.secondary-button {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 750;
}

.icon-button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--muted);
  font-weight: 850;
}

.tab-button.active,
.deck-toggle button.active {
  border-color: var(--blue);
  background: var(--blue);
  color: #ffffff;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.side-panel,
.main-panel {
  min-width: 0;
}

.side-panel {
  display: grid;
  gap: 14px;
}

.tool-panel,
.view {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow);
}

.tool-panel {
  padding: 16px;
}

.panel-head,
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.panel-head h2,
.section-head h2 {
  font-size: 1.18rem;
  line-height: 1.2;
}

.add-form {
  display: grid;
  gap: 10px;
}

.add-form label,
.date-grid label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 750;
}

.add-form textarea,
.add-form input,
.date-grid input {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  padding: 11px 12px;
  outline: 0;
}

.add-form textarea {
  min-height: 142px;
  resize: vertical;
  line-height: 1.45;
}

.primary-button {
  min-height: 46px;
  border-radius: 8px;
  background: var(--green);
  color: #ffffff;
  font-weight: 850;
}

.form-status {
  min-height: 20px;
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.35;
}

.date-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.quick-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.quick-row button[data-range="today"] {
  color: var(--green);
}

.quick-row button[data-range="two-days"] {
  color: var(--gold);
}

.quick-row button[data-range="all"] {
  color: var(--blue);
}

.view {
  display: none;
  min-height: 640px;
  padding: 18px;
}

.view.active {
  display: block;
}

.range-label {
  max-width: 240px;
  color: var(--muted);
  font-size: 0.9rem;
  text-align: right;
}

.utility-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: -4px 0 14px;
}

.utility-row button {
  min-height: 36px;
  color: var(--blue);
}

.word-list {
  display: grid;
  gap: 12px;
}

.date-group {
  display: grid;
  gap: 9px;
}

.date-heading {
  margin: 12px 0 0;
  color: var(--blue);
  font-size: 0.86rem;
  font-weight: 850;
}

.word-card {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--green);
  border-radius: 8px;
  background: var(--surface);
}

.word-top {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.word-top h3 {
  margin: 0;
  font-size: 1.32rem;
  line-height: 1.1;
}

.word-top time {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.82rem;
}

.word-actions {
  display: flex;
  gap: 8px;
  flex: 0 0 auto;
}

.edit-word,
.remove-word {
  min-height: 32px;
  border-radius: 8px;
  padding: 0 10px;
  font-size: 0.82rem;
  font-weight: 800;
}

.edit-word {
  background: #e7eef5;
  color: var(--blue);
}

.remove-word {
  background: #f5e7e5;
  color: var(--red);
}

.detail-grid,
.card-details {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
}

.detail-grid div,
.card-details div {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
}

.detail-grid div:first-child,
.detail-grid div:nth-child(3),
.card-details div:first-child,
.card-details div:nth-child(3) {
  grid-column: 1 / -1;
}

dt {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 850;
  text-transform: uppercase;
}

dd {
  margin: 5px 0 0;
  font-size: 0.94rem;
  line-height: 1.38;
  overflow-wrap: anywhere;
}

.empty-state {
  display: none;
  padding: 36px 12px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

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

.deck-toggle {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: end;
}

.deck-toggle button {
  min-height: 36px;
}

.flashcard {
  min-height: 420px;
  display: grid;
  place-items: stretch;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(145deg, rgba(47, 116, 93, 0.08), transparent 46%),
    #ffffff;
  cursor: pointer;
  user-select: none;
}

.card-face {
  min-height: 420px;
  padding: 26px;
}

.card-front {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 28px;
  text-align: center;
}

.card-front h3,
.card-back h3 {
  margin: 0;
  font-size: 2.25rem;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.card-back {
  display: grid;
  align-content: start;
  gap: 16px;
}

.card-details {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.card-actions {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}

.card-actions button {
  flex: 1;
}

.secondary-button {
  background: var(--surface-strong);
}

.sound-button {
  min-height: 34px;
  max-width: 100%;
  border: 1px solid rgba(47, 95, 143, 0.18);
  border-radius: 8px;
  background: #ffffff;
  color: var(--blue);
  padding: 6px 10px;
  font-size: 0.9rem;
  font-weight: 800;
  line-height: 1.25;
  overflow-wrap: anywhere;
  text-align: left;
}

.sound-button:hover {
  border-color: rgba(47, 95, 143, 0.45);
  background: #eef4f8;
}

.calendar-popover {
  position: absolute;
  z-index: 50;
  width: 280px;
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 18px 42px rgba(23, 31, 38, 0.18);
}

.calendar-head,
.calendar-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.calendar-head strong {
  font-size: 0.95rem;
}

.calendar-head button,
.calendar-footer button,
.calendar-grid button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 800;
}

.calendar-head button {
  width: 36px;
}

.calendar-weekdays,
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
}

.calendar-weekdays span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 850;
  text-align: center;
}

.calendar-grid span {
  min-height: 34px;
}

.calendar-grid button {
  width: 100%;
  padding: 0;
  font-size: 0.84rem;
}

.calendar-grid button.today {
  border-color: var(--green);
  color: var(--green);
}

.calendar-grid button.selected {
  border-color: var(--blue);
  background: var(--blue);
  color: #ffffff;
}

.calendar-footer button {
  flex: 1;
}

.edit-dialog {
  width: min(620px, calc(100% - 28px));
  max-height: calc(100vh - 36px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--ink);
  padding: 0;
}

.edit-dialog::backdrop {
  background: rgba(22, 23, 24, 0.42);
}

.edit-form {
  display: grid;
  gap: 12px;
  padding: 18px;
}

.edit-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 750;
}

.edit-form input,
.edit-form textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  padding: 11px 12px;
  outline: 0;
}

.edit-form textarea {
  resize: vertical;
  line-height: 1.45;
}

.edit-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.dialog-actions {
  display: flex;
  justify-content: end;
  gap: 10px;
  margin-top: 4px;
}

.dialog-actions button {
  min-width: 96px;
}

@media (max-width: 820px) {
  .app-shell {
    width: min(100% - 20px, 640px);
    padding-top: 18px;
  }

  .topbar {
    align-items: start;
    flex-direction: column;
  }

  .stats {
    width: 100%;
    justify-content: stretch;
  }

  .stats article {
    flex: 1;
  }

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

  .view {
    min-height: 520px;
  }
}

@media (max-width: 520px) {
  .app-shell {
    width: calc(100% - 14px);
  }

  .topbar h1 {
    font-size: 1.72rem;
  }

  .view-tabs,
  .card-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .section-head {
    align-items: start;
    flex-direction: column;
  }

  .range-label,
  .deck-toggle {
    width: 100%;
    justify-content: start;
    text-align: left;
  }

  .detail-grid,
  .card-details,
  .edit-grid,
  .date-grid {
    grid-template-columns: 1fr;
  }

  .word-top {
    flex-direction: column;
  }

  .word-actions {
    width: 100%;
  }

  .word-actions button {
    flex: 1;
  }

  .dialog-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .detail-grid div,
  .detail-grid div:first-child,
  .detail-grid div:nth-child(3),
  .card-details div,
  .card-details div:first-child,
  .card-details div:nth-child(3) {
    grid-column: auto;
  }

  .card-face,
  .flashcard {
    min-height: 390px;
  }

  .card-front h3,
  .card-back h3 {
    font-size: 1.85rem;
  }
}
