:root {
  color-scheme: dark;
  --bg: #0f2235;
  --surface: #162b40;
  --card: #10263a;
  --card-ink: #f7fbff;
  --card-muted: #b7cbe0;
  --ink: #f2f8ff;
  --muted: #b2c6da;
  --line: rgba(174, 210, 239, 0.26);
  --green: #53dfaa;
  --green-soft: rgba(83, 223, 170, 0.16);
  --red: #ff8a7a;
  --red-soft: rgba(255, 138, 122, 0.16);
  --blue: #1185fe;
  --blue-soft: rgba(17, 133, 254, 0.18);
  --shadow: 0 24px 70px rgba(0, 9, 18, 0.38);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  letter-spacing: 0;
}

button {
  font: inherit;
}

[hidden] {
  display: none !important;
}

.app-shell {
  width: min(100%, 560px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px 18px 32px;
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 18px;
}

.legal-link {
  justify-self: start;
  color: rgba(242, 248, 255, 0.58);
  font-size: 12px;
  line-height: 1.2;
  text-decoration: none;
}

.legal-link:hover {
  color: rgba(242, 248, 255, 0.88);
  text-decoration: underline;
}

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

.topbar-brand {
  display: grid;
  gap: 8px;
  justify-items: start;
}

.topbar-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.language-switcher {
  display: inline-grid;
  grid-template-columns: repeat(2, 1fr);
  min-height: 46px;
  overflow: hidden;
  background: rgba(15, 35, 57, 0.66);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.language-button {
  min-width: 48px;
  padding: 0 12px;
  color: var(--muted);
  background: transparent;
  border: 0;
  cursor: pointer;
  font-weight: 850;
}

.language-button[aria-pressed="true"] {
  color: #ffffff;
  background: var(--blue);
}

.eyebrow {
  margin: 0 0 4px;
  color: #7fc2ff;
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 9vw, 3.4rem);
  line-height: 0.94;
  color: var(--ink);
}

.ghost-button,
.copy-button,
.account-button,
.account-tab,
.icon-button,
.reveal-button {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background 160ms ease;
}

.ghost-button {
  padding: 0 16px;
  color: var(--ink);
  background: rgba(15, 35, 57, 0.66);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.account-button {
  padding: 0 14px;
  color: var(--ink);
  background: rgba(15, 35, 57, 0.66);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
  font-size: 0.88rem;
  font-weight: 850;
}

.profile-avatar {
  width: 46px;
  height: 46px;
  padding: 0;
  display: grid;
  place-items: center;
  color: #ffffff;
  background: linear-gradient(135deg, #1185fe, #53dfaa);
  border: 1px solid rgba(139, 208, 255, 0.58);
  border-radius: 50%;
  box-shadow: 0 12px 26px rgba(17, 133, 254, 0.24);
  cursor: pointer;
  font-weight: 900;
}

.profile-avatar span {
  transform: translateY(-1px);
}

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

.copy-button {
  padding: 0 12px;
  color: var(--ink);
  background: rgba(15, 35, 57, 0.66);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
  font-size: 0.9rem;
  font-weight: 800;
}

.copy-button:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

.icon-button {
  width: 46px;
  padding: 0;
  color: var(--ink);
  background: rgba(15, 35, 57, 0.66);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
  font-size: 1.45rem;
  font-weight: 850;
  line-height: 1;
}

.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.38;
}

.repeat-under-card {
  align-self: center;
  margin-top: 10px;
}

.primary-ghost {
  color: #ffffff;
  background: var(--blue);
  border-color: rgba(139, 208, 255, 0.58);
}

.danger-ghost {
  color: #ffffff;
  background: rgba(255, 138, 122, 0.18);
  border-color: rgba(255, 138, 122, 0.42);
}

.reveal-button {
  width: 100%;
  margin-top: 18px;
  padding: 0 18px;
  color: #ffffff;
  background: var(--blue);
  border-color: rgba(139, 208, 255, 0.58);
  font-weight: 800;
  box-shadow: 0 14px 34px rgba(17, 133, 254, 0.26);
}

.ghost-button:hover,
.account-button:hover,
.account-tab:hover,
.profile-avatar:hover,
.copy-button:not(:disabled):hover,
.icon-button:not(:disabled):hover,
.reveal-button:hover {
  transform: translateY(-1px);
  border-color: rgba(157, 217, 255, 0.72);
}

.scoreboard {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.scoreboard > div {
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.07);
}

.metric-value,
.metric-label {
  display: block;
}

.metric-value {
  font-size: 1.28rem;
  font-weight: 850;
}

.metric-value.known {
  color: var(--green);
}

.metric-value.missed {
  color: var(--red);
}

.metric-label {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.78rem;
}

.study-panel,
.finished-panel,
.evaluation-panel,
.auth-panel,
.profile-panel,
.converter-panel {
  display: flex;
  flex-direction: column;
}

.progress-line {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin: 2px 2px 12px;
  color: var(--muted);
  font-size: 0.88rem;
}

.card-area {
  position: relative;
  width: 100%;
  height: clamp(320px, 56vh, 500px);
  perspective: 1200px;
  touch-action: pan-y;
  user-select: none;
}

.card-stage {
  position: absolute;
  inset: 0;
  transform-origin: 50% 78%;
  transition:
    transform 190ms ease,
    opacity 190ms ease;
  cursor: grab;
}

.card-stage:active {
  cursor: grabbing;
}

.flashcard {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 360ms cubic-bezier(0.2, 0.72, 0.18, 1);
}

.flashcard.is-flipped {
  transform: rotateY(180deg);
}

.card-face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: clamp(24px, 8vw, 46px);
  background: var(--card);
  border: 1px solid rgba(174, 210, 239, 0.22);
  border-radius: 8px;
  box-shadow: var(--shadow);
  backface-visibility: hidden;
}

.card-front {
  grid-template-rows: 0.7fr auto 0.9fr;
}

.card-front .reading {
  align-self: end;
  color: var(--card-muted);
  font-size: clamp(1.05rem, 4vw, 1.5rem);
  font-weight: 750;
  line-height: 1.35;
  text-align: center;
}

.term {
  align-self: center;
  width: 100%;
  color: var(--card-ink);
  font-family:
    "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif CJK JP", serif;
  font-size: clamp(4rem, 22vw, 8.5rem);
  font-weight: 700;
  line-height: 1.05;
  text-align: center;
  overflow: hidden;
  text-wrap: nowrap;
  word-break: keep-all;
  white-space: nowrap;
}

.term[data-size="long"] {
  font-size: clamp(3rem, 15vw, 6.4rem);
}

.term[data-size="wide"] {
  font-size: clamp(2.4rem, 11vw, 4.8rem);
}

.card-back {
  transform: rotateY(180deg);
}

.meaning {
  max-width: 100%;
  color: var(--card-ink);
  font-size: clamp(2.15rem, 10vw, 4.45rem);
  font-weight: 850;
  line-height: 1.05;
  text-align: center;
  overflow-wrap: anywhere;
}

.meaning[data-size="long"] {
  font-size: clamp(1.7rem, 7.5vw, 3.25rem);
}

.meaning[data-size="wide"] {
  font-size: clamp(1.35rem, 5.6vw, 2.45rem);
}

.swipe-badge {
  position: absolute;
  z-index: 4;
  top: 22px;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 850;
  opacity: 0;
  transform: translateY(-6px);
  transition:
    opacity 130ms ease,
    transform 130ms ease;
  pointer-events: none;
}

.swipe-left {
  left: 18px;
  color: var(--red);
  background: var(--red-soft);
  border: 1px solid rgba(255, 138, 122, 0.26);
}

.swipe-right {
  right: 18px;
  color: var(--green);
  background: var(--green-soft);
  border: 1px solid rgba(83, 223, 170, 0.26);
}

.swipe-badge.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.finished-panel {
  margin-top: 18px;
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  gap: 14px;
  text-align: center;
}

.finished-panel h2 {
  font-size: 1.8rem;
}

.finished-panel p {
  color: var(--muted);
}

.evaluation-panel {
  gap: 18px;
}

.evaluation-header,
.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 16px;
}

.evaluation-actions,
.profile-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.evaluation-header h2,
.panel-header h2 {
  font-size: clamp(1.7rem, 6vw, 2.5rem);
}

.auth-panel,
.profile-panel {
  gap: 18px;
}

.account-card {
  display: grid;
  gap: 16px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.07);
}

.account-card h3 {
  margin: 0;
  font-size: 1.05rem;
}

.account-tabs {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  min-height: 46px;
  overflow: hidden;
  background: rgba(15, 35, 57, 0.66);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.account-tab {
  padding: 0 12px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 0;
  font-weight: 850;
}

.account-tab[aria-pressed="true"] {
  color: #ffffff;
  background: var(--blue);
}

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

.compact-form {
  gap: 9px;
}

.account-label {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 750;
}

.account-input {
  width: 100%;
  min-height: 46px;
  padding: 0 12px;
  color: var(--ink);
  background: rgba(15, 35, 57, 0.66);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 16px;
  line-height: 1.4;
  outline: none;
}

.account-input:focus {
  border-color: rgba(157, 217, 255, 0.72);
  box-shadow: 0 0 0 3px var(--blue-soft);
}

.homepage-field {
  position: absolute;
  left: -10000px;
  top: auto;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.turnstile-box {
  min-height: 65px;
}

.account-message {
  min-height: 1.25rem;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.account-message.is-error {
  color: var(--red);
}

.account-message.is-success {
  color: var(--green);
}

.profile-grid {
  display: grid;
  gap: 14px;
}

.muted-text {
  color: var(--muted);
  line-height: 1.45;
}

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

.deck-item {
  padding: 12px;
  background: rgba(15, 35, 57, 0.66);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.deck-item strong,
.deck-item span {
  display: block;
}

.deck-item span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.86rem;
}

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

.result-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.result-group h3 {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  color: var(--ink);
  font-size: 1rem;
}

.result-group h3 span {
  min-width: 34px;
  padding: 3px 8px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 0.86rem;
  text-align: center;
}

.mini-button {
  min-height: 34px;
  padding: 0 12px;
  color: #ffffff;
  background: var(--blue);
  border: 1px solid rgba(139, 208, 255, 0.58);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 800;
}

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

.vocab-row {
  display: grid;
  grid-template-columns: minmax(72px, auto) 1fr;
  gap: 12px;
  align-items: center;
  padding: 12px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.vocab-term {
  min-width: 0;
  color: var(--card-ink);
  font-family:
    "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif CJK JP", serif;
  font-size: 1.55rem;
  font-weight: 700;
  line-height: 1.05;
  overflow: hidden;
  text-wrap: nowrap;
  word-break: keep-all;
  white-space: nowrap;
}

.vocab-meta {
  min-width: 0;
}

.vocab-reading,
.vocab-meaning {
  display: block;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.vocab-reading {
  color: var(--muted);
  font-size: 0.9rem;
}

.vocab-meaning {
  margin-top: 2px;
  color: var(--ink);
  font-weight: 700;
}

.empty-result {
  padding: 12px;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: 8px;
}

.converter-panel {
  gap: 10px;
  margin-top: 4px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.07);
}

.converter-panel h2 {
  margin: 0;
  font-size: 1.15rem;
}

.kana-output {
  min-height: 58px;
  padding: 14px;
  color: var(--card-ink);
  background: var(--card);
  border: 1px solid rgba(174, 210, 239, 0.22);
  border-radius: 8px;
  font-family:
    "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif CJK JP", serif;
  font-size: 24px;
  font-weight: 700;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.converter-label {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 750;
}

.romaji-input {
  width: 100%;
  min-height: 46px;
  padding: 0 12px;
  color: var(--ink);
  background: rgba(15, 35, 57, 0.66);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 16px;
  line-height: 1.4;
  outline: none;
}

.romaji-input:focus {
  border-color: rgba(157, 217, 255, 0.72);
  box-shadow: 0 0 0 3px var(--blue-soft);
}

@media (max-width: 420px) {
  .app-shell {
    padding: 18px 12px 24px;
  }

  .scoreboard > div {
    padding: 10px 8px;
  }

  .metric-label {
    font-size: 0.72rem;
  }

  .card-area {
    height: clamp(270px, 48vh, 340px);
  }

  .topbar,
  .evaluation-header,
  .panel-header {
    align-items: start;
    flex-direction: column;
  }

  .topbar-actions,
  .evaluation-actions,
  .profile-actions {
    width: 100%;
    justify-content: stretch;
  }

  .language-switcher {
    flex: 1 0 100%;
  }

  .topbar-actions .ghost-button,
  .topbar-actions .icon-button,
  .evaluation-actions .ghost-button,
  .profile-actions .ghost-button,
  .panel-header > .ghost-button {
    flex: 1;
  }

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

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

  .result-heading {
    align-items: stretch;
    flex-direction: column;
  }
}
