:root {
  color-scheme: dark;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top, rgba(124, 58, 237, 0.18), transparent 35%),
    linear-gradient(180deg, #0b1020 0%, #11182d 45%, #0c1222 100%);
  color: #edf2ff;
  --bg: #0f172a;
  --panel: rgba(15, 23, 42, 0.82);
  --panel-strong: rgba(17, 24, 39, 0.96);
  --panel-soft: rgba(30, 41, 59, 0.75);
  --border: rgba(148, 163, 184, 0.18);
  --text-main: #edf2ff;
  --text-soft: #9aa8c7;
  --accent: linear-gradient(135deg, #7c3aed 0%, #2563eb 100%);
  --accent-solid: #5b7cff;
  --danger: #ef4444;
  --success: #22c55e;
  --shadow: 0 24px 60px rgba(2, 6, 23, 0.45);
  --viewport-height: 100dvh;
  --viewport-offset-top: 0px;
  --topbar-height: 110px;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  color: var(--text-main);
  background: var(--bg);
}

body.keyboard-open {
  overflow: hidden;
}

button,
input {
  font: inherit;
}

button {
  border: none;
  border-radius: 18px;
  padding: 1rem 1.15rem;
  background: var(--accent);
  color: white;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease, opacity 0.18s ease, background 0.18s ease;
  box-shadow: 0 16px 30px rgba(37, 99, 235, 0.28);
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

input {
  width: 100%;
  border-radius: 18px;
  border: 1px solid rgba(148, 163, 184, 0.2);
  padding: 1rem 3rem 1rem 1rem;
  color: var(--text-main);
  background: rgba(15, 23, 42, 0.86);
  outline: none;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

input:focus {
  border-color: rgba(96, 165, 250, 0.9);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.15);
}

input::placeholder {
  color: #6b7a99;
}

label {
  display: grid;
  gap: 0.55rem;
  font-weight: 600;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0.1rem;
  font-size: clamp(1.7rem, 6vw, 2.4rem);
  line-height: 1.05;
}

h2 {
  margin-bottom: 0.35rem;
  font-size: clamp(1.5rem, 5vw, 2rem);
}

h3 {
  margin-bottom: 0.3rem;
}

main {
  display: grid;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.app-shell {
  max-width: 920px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: 1rem 1rem 3rem;
  display: flex;
  flex-direction: column;
}

.topbar,
.menu-card,
.study-card,
.preview-card,
.word-item,
.loading-panel,
.confirm-dialog {
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.topbar {
  position: sticky;
  top: max(0.75rem, calc(var(--viewport-offset-top) + 0.75rem));
  z-index: 20;
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 48px;
  align-items: center;
  gap: 0.9rem;
  min-height: 82px;
  margin-bottom: 1.25rem;
  padding: 1rem 1.1rem;
  border-radius: 28px;
}

.title-block {
  min-width: 0;
  text-align: center;
}

.title-block h1,
.title-block p {
  overflow-wrap: anywhere;
}

.icon-button {
  width: 46px;
  height: 46px;
  padding: 0;
  border-radius: 999px;
  background: rgba(30, 41, 59, 0.92);
  color: var(--text-main);
  border: 1px solid rgba(148, 163, 184, 0.18);
  flex: 0 0 auto;
  box-shadow: none;
}

.icon-button.is-placeholder {
  visibility: hidden;
  pointer-events: none;
}

.topbar::after {
  content: "";
  width: 46px;
  height: 46px;
}

.subtitle,
.helper-text,
.menu-copy,
.word-item p,
.preview-translation {
  color: var(--text-soft);
}

.eyebrow {
  margin-bottom: 0.45rem;
  color: var(--text-soft);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.74rem;
  font-weight: 700;
}

.stack,
.stack-lg {
  display: grid;
}

.stack {
  gap: 0.9rem;
}

.stack-lg {
  gap: 1.2rem;
}

.preview-card,
.word-item {
  border-radius: 28px;
  padding: 1.4rem;
}

.home-grid {
  display: grid;
  gap: 1rem;
}

.menu-card {
  text-align: left;
  border-radius: 26px;
  padding: 1.35rem;
  color: var(--text-main);
  display: grid;
  gap: 0.5rem;
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.94) 0%, rgba(30, 41, 59, 0.82) 100%);
}

.menu-card.accent-card {
  background: linear-gradient(135deg, rgba(91, 124, 255, 0.32) 0%, rgba(124, 58, 237, 0.28) 100%), rgba(15, 23, 42, 0.9);
}

.menu-icon {
  width: 2.5rem;
  height: 2.5rem;
  display: inline-grid;
  place-items: center;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.08);
  font-size: 1.1rem;
}

.menu-title {
  display: block;
  font-size: 1.18rem;
}

.panel-header,
.words-header,
.word-item-top,
.button-row,
.preview-heading,
.preview-heading-main,
.word-item-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}

.panel-header-end {
  justify-content: flex-end;
}

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

.preview-heading-main {
  width: 100%;
  align-items: flex-start;
}

.preview-heading-copy {
  display: grid;
  gap: 0.32rem;
}

.preview-heading-copy h3 {
  margin: 0;
  font-size: clamp(2rem, 6vw, 3rem);
  line-height: 1.02;
}

.preview-translation {
  margin: 0;
  font-size: clamp(1.18rem, 3.35vw, 1.42rem);
  line-height: 1.18;
}

.score-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 92px;
  padding: 0.55rem 0.85rem;
  border-radius: 999px;
  background: rgba(34, 197, 94, 0.14);
  color: #baf7cc;
  border: 1px solid rgba(34, 197, 94, 0.25);
  font-weight: 700;
  font-size: 0.9rem;
}

.definition-card {
  padding: 1.1rem 1.15rem;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid rgba(148, 163, 184, 0.08);
}

.definition-card p {
  margin: 0;
  color: #d7e0f5;
  font-size: 1rem;
  line-height: 1.55;
}

.examples-section strong {
  display: inline-block;
  margin-bottom: 0.05rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.18);
  color: #a9c6ff;
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 700;
  border: 1px solid rgba(96, 165, 250, 0.18);
}

.badge.muted {
  background: rgba(148, 163, 184, 0.12);
  color: #ced8ee;
}

.word-item-badges {
  display: grid;
  gap: 0.45rem;
  justify-items: end;
}

.repeat-screen {
  flex: 1;
  min-height: 0;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.study-card {
  width: 100%;
  min-height: 300px;
  height: 100%;
  min-height: 0;
  display: flex;
  align-items: stretch;
  overflow: hidden;
  border-radius: 30px;
  padding: 1.35rem;
  text-align: center;
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.98) 0%, rgba(30, 41, 59, 0.92) 100%);
  cursor: pointer;
}

.study-card.disabled {
  cursor: default;
}

.study-card:focus-visible {
  outline: 2px solid rgba(91, 124, 255, 0.85);
  outline-offset: 3px;
}

.study-front,
.study-back {
  display: grid;
  flex: 1;
  width: 100%;
  min-height: 0;
  gap: 0.8rem;
}

.study-front {
  align-content: center;
  justify-items: center;
}

.study-front h3 {
  margin: 0;
  font-size: clamp(2.1rem, 6vw, 3.2rem);
}

.face-label {
  justify-self: center;
  display: inline-flex;
  width: fit-content;
  border-radius: 999px;
  background: rgba(91, 124, 255, 0.14);
  color: #bfd1ff;
  padding: 0.32rem 0.72rem;
  font-size: 0.75rem;
  font-weight: 700;
  border: 1px solid rgba(91, 124, 255, 0.18);
}

.study-back {
  align-content: stretch;
  overflow: auto;
}

.study-back-stack,
.word-meta-card {
  display: grid;
  gap: 0.85rem;
  width: 100%;
}

.study-back-stack {
  min-height: 100%;
  align-content: stretch;
  gap: 0.72rem;
}

.study-back-copy {
  display: grid;
  gap: 0.72rem;
  align-content: start;
}

.study-back-heading {
  display: grid;
  width: 100%;
  justify-items: start;
  align-content: start;
  gap: 0.12rem;
  margin-bottom: 0.2rem;
  text-align: left;
}

.study-back .definition-card,
.study-back .examples-section {
  width: 100%;
  text-align: left;
}

.study-back-heading h3 {
  margin: 0;
  font-size: clamp(1.05rem, 3vw, 1.2rem);
  line-height: 1.1;
  color: #7f90b3;
  font-weight: 600;
}

.study-back .preview-translation {
  width: 100%;
  margin: 0.04rem 0 0;
  padding-bottom: 0.2rem;
  color: #f3f7ff;
  font-size: clamp(1.44rem, 4.4vw, 1.88rem);
  line-height: 1.08;
  font-weight: 750;
  white-space: normal;
  overflow-wrap: normal;
  word-break: normal;
  hyphens: none;
}

.study-back .definition-card,
.word-meta-card div {
  display: grid;
  gap: 0.2rem;
  text-align: left;
  padding: 0.8rem 0.95rem;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(148, 163, 184, 0.08);
}

.study-back .definition-card p {
  font-size: 0.94rem;
  line-height: 1.48;
  color: #b8c5e2;
  font-weight: 450;
}

.study-back .definition-card {
  margin-bottom: 0.16rem;
}

.study-examples {
  gap: 0.12rem;
}

.study-examples strong {
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #7f90b3;
}

.study-example-lines {
  margin: 0;
  color: #9fb0d3;
  line-height: 1.16;
  white-space: pre-line;
  font-size: 0.92rem;
  font-weight: 450;
}

.word-meta-card span,
ul {
  color: #d7e0f5;
}

.rating-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
  margin-top: auto;
  padding-top: 0.4rem;
}

.secondary-button {
  background: linear-gradient(135deg, #334155 0%, #1e293b 100%);
}

.ghost-button {
  background: rgba(30, 41, 59, 0.92);
  color: var(--text-main);
  border: 1px solid rgba(148, 163, 184, 0.18);
  box-shadow: none;
}

.danger-button {
  background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
}

.delete-word-button {
  min-width: 96px;
  color: #ffd6d6;
}

.primary-button,
.wide-button {
  width: 100%;
}

.add-screen {
  flex: 1;
  min-height: 0;
  align-content: center;
}

.add-form {
  gap: 1rem;
}

.add-form-centered {
  display: grid;
  place-items: center;
  min-height: min(46vh, 420px);
}

body.keyboard-open .add-form-centered {
  align-content: start;
  padding-top: clamp(1rem, 6vh, 3.5rem);
}

.add-input-row {
  position: relative;
  width: min(100%, 640px);
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: center;
  padding-inline: 4.1rem;
}

.add-word-input {
  border: none;
  border-bottom: 1.5px solid rgba(148, 163, 184, 0.42);
  outline: none;
  border-radius: 0;
  padding: 0.9rem 0;
  background: transparent;
  box-shadow: none;
  font-size: clamp(2rem, 8vw, 3.8rem);
  font-weight: 700;
  line-height: 1.05;
  text-align: center;
  transition: border-color 0.18s ease;
}

.add-word-input:focus {
  outline: none;
  border-bottom-color: rgba(96, 165, 250, 0.95);
  box-shadow: none;
}

.add-word-input::placeholder {
  color: rgba(154, 168, 199, 0.24);
}

.submit-arrow {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 4.1rem;
  height: 4.1rem;
  padding: 0;
  border-radius: 999px;
  background: transparent;
  color: #eef4ff;
  border: none;
  box-shadow: none;
  font-size: 2.5rem;
  font-weight: 500;
}

.submit-arrow:hover:not(:disabled) {
  transform: translateY(-50%);
}

.add-preview-state {
  display: none;
}

.preview-card ul {
  margin: 0.25rem 0 0;
  padding-left: 1.15rem;
}

.preview-card li + li {
  margin-top: 0.55rem;
}

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

.words-list {
  display: grid;
  gap: 0.9rem;
}

.word-item-top {
  align-items: flex-start;
  margin-bottom: 1rem;
}

.word-item h3 {
  margin-bottom: 0.25rem;
}

.empty-state {
  color: var(--text-soft);
  padding: 1rem 0;
}

.loading-overlay,
.confirm-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(2, 6, 23, 0.78);
  backdrop-filter: blur(10px);
  z-index: 50;
}

.loading-panel,
.confirm-dialog {
  width: min(420px, 100%);
  padding: 2rem 1.5rem;
  border-radius: 28px;
  text-align: center;
}

.confirm-dialog {
  text-align: left;
}

.confirm-dialog h2 {
  margin-bottom: 0.5rem;
}

.spinner {
  width: 54px;
  height: 54px;
  margin: 0 auto 1rem;
  border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, 0.1);
  border-top-color: #8ab4ff;
  animation: spin 0.9s linear infinite;
}

.hidden {
  display: none !important;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (min-width: 700px) {
  .home-grid,
  .word-meta-card {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 699px) {
  .word-item-top,
  .panel-header,
  .words-header,
  .preview-heading-main,
  .word-item-actions {
    grid-template-columns: 1fr;
    display: grid;
    align-items: start;
  }

  .word-item-badges {
    justify-items: start;
  }

  .preview-actions,
  .confirm-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .topbar {
    grid-template-columns: 44px minmax(0, 1fr) 44px;
    min-height: 78px;
    padding: 0.9rem;
  }

  .submit-arrow {
    width: 3.6rem;
    height: 3.6rem;
    font-size: 2.2rem;
  }

  .icon-button,
  .topbar::after {
    width: 44px;
    height: 44px;
  }

  h1 {
    font-size: clamp(1.45rem, 7vw, 2rem);
  }
}
