:root {
  --pink: #FF00AA;
  --pink-light: #FFD4F1;
  --purple: #AA00FF;
  --purple-light: #E4D5F7;
  --bg: #F4F4F4;
  --card: #FFFFFF;
  --text: #333333;
  --muted: #6B7079;
  --border: #CAD0D6;
  --header-border: #aaa;
  --footer-border: #aaa;
  --accent-hover: #FF26B4;
  --focus: #FFD4F1;
  --edge: #B9007B;
  --btn-bg: #E6E9ED;
  --btn-bg-hover: #DADEE4;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --radius: 16px;
}

/* Visibility is driven by the `hidden` attribute everywhere */
[hidden] { display: none !important; }

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: "Noto Sans", "Noto Sans JP", "Noto Sans SC", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  text-align: center;
}

/* -------------------------------------------------------------------------- */
/* HEADER ------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

header {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1.25rem;
  background: #fff;
  color: var(--text);
  border-bottom: 1px solid var(--header-border);
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.brand-title {
  margin: 0;
  padding: 0.3rem 0.7rem;
  font-size: 1.05rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand-title strong {
  font-weight: 800;
  letter-spacing: 0.06em;
}
.brand-title span {
  font-weight: 500;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--card);
  color: var(--text);
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  transition: background .15s, transform .05s;
}
.icon-btn:hover { border-color: var(--pink); box-shadow: 0 0 0 3px var(--focus), 0 4px 14px rgba(0, 0, 0, 0.15); }
.icon-btn:active { transform: translateY(2px); }
.icon-btn:disabled { cursor: default; }
.icon-btn:disabled:hover { border-color: var(--border); box-shadow: none; }
.icon-btn:disabled:active { transform: none; }

main {
  flex: 1;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

/* -------------------------------------------------------------------------- */
/* SENTENCE CARD ------------------------------------------------------------ */
/* -------------------------------------------------------------------------- */

.card {
  position: relative;
  overflow: hidden;
  width: 100%;
  min-height: 260px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 0 1.25rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-body {
  flex: 1;
  align-self: stretch;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
}

/* -------------------------------------------------------------------------- */
/* VOCAB PANEL -------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

.vocab {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  align-self: stretch;
  width: 100%;
  margin-bottom: 1rem;
  padding: 1rem 0 2rem;
  background: var(--purple);
  border-top-left-radius: var(--radius);
  border-top-right-radius: var(--radius);
}
.vocab-word {
  font-size: 4rem;
  color: #fff;
  line-height: 1.2;
  cursor: pointer;
  border-bottom: 2px dotted rgba(255, 255, 255, 0.7);
}
.vocab-word.no-custom-font {
  font-family: inherit;
}
.vocab-details {
  margin: .5rem 0;
  text-align: left;
  color: #fff;
  font-size: 1.25rem;
  line-height: 1.5;
}
.vocab-audio {
  display: flex;
  margin-top: 0.75rem;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
}
.vocab-progress {
  position: absolute;
  right: 0.9rem;
  top: 0.55rem;
  font-size: 0.9rem;
  line-height: 1;
  color: #fff;
  opacity: 0.75;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  user-select: none;
  pointer-events: none;
}
.vocab-level {
  position: absolute;
  left: 0.9rem;
  top: 0.55rem;
  font-size: 0.9rem;
  line-height: 1;
  color: #fff;
  opacity: 0.75;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  user-select: none;
  pointer-events: none;
}

/* -------------------------------------------------------------------------- */
/* SENTENCE PANEL ----------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

.ja-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  width: 100%;
  padding: 0 1rem;
}
.ja-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 0.3rem;
}
#ja {
  margin: 0;
  font-size: clamp(1.25rem, 2.5vw, 2rem);
  font-weight: 500;
  line-height: 1.5;
  overflow-wrap: anywhere;
  text-align: center;
  transition: background 0.4s ease, box-shadow 0.4s ease, border-radius 0.4s ease;
  padding: 0.25rem 0.5rem;
}
#ja.highlight {
  background: var(--pink-light);
  box-shadow: 0 0 0 6px var(--pink-light);
  border-radius: 6px;
}
#ja mark.vocab-hit {
  background: var(--purple-light);
  color: inherit;
  border-radius: 3px;
  padding: 0 0.06em;
}
#ja.no-custom-font {
  font-family: inherit;
}
.copy-ja-btn,
.audio-btn {
  flex: 0 0 auto;
  width: 2.25rem;
  height: 2.25rem;
}
.audio-btn.playing {
  border-color: var(--pink);
  background: var(--pink);
  color: #fff;
  box-shadow: 0 0 0 3px var(--focus);
}
.audio-btn.loading {
  opacity: 0.55;
}
.spinner {
  width: 3rem;
  height: 3rem;
  margin: 1rem auto;
  border: 4px solid var(--pink-light);
  border-top-color: var(--pink);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
#ja .spinner { margin: 0 auto; }
@keyframes spin { to { transform: rotate(360deg); } }
#en {
  margin: 0;
  padding: 0 2rem;
  font-size: clamp(1rem, 3.5vw, 1.4rem);
  color: var(--muted);
  line-height: 1.5;
  overflow-wrap: anywhere;
}

/* -------------------------------------------------------------------------- */
/* NAVIGATION AND REVEAL CONTROLS ------------------------------------------- */
/* -------------------------------------------------------------------------- */

.controls {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
}
.control-main {
  grid-column: 2;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  justify-self: center;
}
#backBtn { grid-column: 1; justify-self: start; }
#nextBtn { grid-column: 3; justify-self: end; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 1.25rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--btn-bg);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background .15s, transform .05s;
}
.btn:hover { background: var(--btn-bg-hover); border-color: var(--pink); box-shadow: 0 0 0 3px var(--focus), 0 4px 14px rgba(0, 0, 0, 0.15); }
.btn:active { transform: translateY(2px); }
.btn:disabled {
  opacity: 0.4;
  cursor: default;
  box-shadow: none;
  transform: none;
  border-color: var(--border);
  background: var(--btn-bg);
}
.btn:disabled:hover {
  background: var(--btn-bg);
  border-color: var(--border);
  box-shadow: none;
}
.btn-primary {
  background: var(--pink);
  border-color: var(--edge);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-icon {
  padding: 0;
  min-width: 3rem;
  background: transparent;
}
.btn-icon:hover { background: transparent; }
.btn-sm {
  min-height: 40px;
  padding: 0 0.85rem;
  font-size: 0.85rem;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

/* Reveal button doubles as a two-step progress indicator. */
#revealBtn {
  position: relative;
  overflow: hidden;
  isolation: isolate;
}
#revealBtn svg {
  position: relative;
  z-index: 1;
  color: var(--muted);
}
#revealBtn:hover {
  border-color: var(--purple);
  box-shadow: 0 0 0 3px var(--purple-light), 0 4px 14px rgba(0, 0, 0, 0.15);
}
.reveal-fill {
  position: absolute;
  inset: auto 0 0 auto;
  height: 6px;
  width: 100%;
  border-top: 2px solid var(--purple);
  background: var(--purple-light);
  pointer-events: none;
  transition: width .35s cubic-bezier(.4, 0, .2, 1);
}
#revealBtn.reveal-no-transition .reveal-fill { transition: none; }
#revealBtn[data-reveal-step="0"] .reveal-fill { width: 100%; }
#revealBtn[data-reveal-step="1"] .reveal-fill { width: 50%; }
#revealBtn[data-reveal-step="2"] .reveal-fill { width: 0; }
#revealBtn.reveal-idle .reveal-fill { display: none; }

@media (prefers-reduced-motion: reduce) {
  .reveal-fill { transition: none; }
}

/* -------------------------------------------------------------------------- */
/* FOOTER ------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

footer {
  position: sticky;
  bottom: 0;
  z-index: 3;
  min-height: 4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 1rem;
  background: #fff;
  border-top: 1px solid var(--footer-border);
  box-shadow: 0 -12px 30px -24px rgba(35, 28, 18, 0.45);
}
#help-btn {
  position: absolute;
  right: 1rem;
  top: calc(50% - 1.375rem);
}
.refresh-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
  width: 1.5rem;
  height: 1.5rem;
  margin-left: 0.15rem;
  padding: 0 0 3px;
  border: none;
  border-radius: 4px;
  background: none;
  color: var(--muted);
  cursor: pointer;
  transition: color .15s, transform .05s;
}
.refresh-btn:hover { color: var(--pink); }
.refresh-btn:active { transform: translateY(1px); }
.refresh-btn:disabled {
  opacity: 0.45;
  cursor: default;
}
.refresh-btn:disabled:hover { color: var(--muted); }
.refresh-btn:disabled:active { transform: none; }
.sentence-info {
  font-size: 0.8rem;
  color: var(--muted);
  letter-spacing: 0.02em;
}
.sentence-info-sep {
  display: inline-block;
  font-size: 1.3em;
  line-height: 1;
  vertical-align: middle;
  margin: 0 0.35em;
}
@media (max-width: 600px) {
  .sentence-info-sep { display: none; }
  .sentence-info-mode { display: block; }
}

/* -------------------------------------------------------------------------- */
/* DIALOGS ------------------------------------------------------------------ */
/* -------------------------------------------------------------------------- */

#overlay {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.45);
  z-index: 5;
}
#settingsDialog,
#helpDialog {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 10;
  width: min(92vw, 420px);
  max-height: 88vh;
  overflow-y: auto;
  padding: 1.5rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
  text-align: left;
}
.dialog-title {
  margin: 0 0 1.25rem;
  padding-bottom: 0.75rem;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}
.dialog-note {
  margin: 0 0 1rem;
  font-size: 0.9rem;
  color: var(--muted);
}
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  margin-top: 1.5rem;
}

/* -------------------------------------------------------------------------- */
/* SETTINGS DIALOG ---------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

.field-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 2rem;
}
.field-row .field {
  margin-bottom: 0;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 1rem;
}
.field > label {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.field select {
  width: 100%;
  padding: 0.6rem 0.7rem;
  font: inherit;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 4px;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--pink);
  box-shadow: 0 0 0 3px var(--focus);
}
.checkbox-field {
  flex-direction: row;
  align-items: flex-start;
}
.checkbox-label {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  margin: 0;
  cursor: pointer;
}
.checkbox-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin-top: 0.1rem;
  accent-color: var(--pink);
  flex-shrink: 0;
}
.checkbox-label span {
  font-size: 0.9rem;
  color: var(--text);
  line-height: 1.4;
  text-transform: none;
  letter-spacing: normal;
  font-weight: 400;
}
#settingsDialog .dialog-actions {
  margin-top: 3rem;
}

/* -------------------------------------------------------------------------- */
/* HELP DIALOG -------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

.shortcut-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin: 0 0 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}
.shortcut {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.95rem;
  color: var(--text);
}
.shortcut .keys {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}
.shortcut .keys .key-sep {
  color: var(--muted);
  font-size: 0.8rem;
}
.shortcut kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  min-width: 2rem;
  padding: 0.2rem 0.5rem;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  text-align: center;
  color: var(--text);
  background: var(--btn-bg);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
}
#helpDialog .dialog-note {
  font-size: 0.8rem;
}

/* -------------------------------------------------------------------------- */
/* ALL DONE MESSAGE --------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

.state-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 0;
}
.state-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
}
.state-box .state-icon svg { color: var(--pink); }
.state-title {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
}
.state-sub {
  margin: 0;
  font-size: 1.05rem;
  color: var(--muted);
  line-height: 1.5;
}
.state-range {
  width: min(100%, 11rem);
  margin: 0 0;
  font-size: 1rem;
  text-align: left;
}
.state-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.75rem;
  margin-top: 4rem;
}

/* -------------------------------------------------------------------------- */
/* FONTS -------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

.font-kosugi { font-family: 'Kosugi Maru', 'Hiragino Maru Gothic ProN', 'Yu Gothic', Meiryo, sans-serif; }
.font-mplus  { font-family: 'M PLUS 1p', 'Hiragino Kaku Gothic ProN', 'Yu Gothic', Meiryo, sans-serif; }
.font-noto   { font-family: 'Noto Sans JP', 'Noto Sans CJK JP', 'Hiragino Sans', 'Yu Gothic', sans-serif; }
.font-zen    { font-family: 'Zen Kaku Gothic New', 'Hiragino Sans', 'Yu Gothic', Meiryo, sans-serif; }
.font-boku   { font-family: 'Yuji Boku', 'Hiragino Mincho ProN', 'Yu Mincho', 'Noto Serif JP', serif; }

/* -------------------------------------------------------------------------- */
/* CLIPBOARD FALLBACK ------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

.copy-fallback {
  position: fixed;
  top: 0;
  left: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

/* -------------------------------------------------------------------------- */
/* TOAST -------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  z-index: 10;
  padding: 0.6rem 1.1rem;
  border-radius: 999px;
  background: var(--purple);
  color: #fff;
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
  opacity: 0;
  transform: translate(-50%, 0.5rem);
  transition: opacity .18s ease, transform .18s ease;
  pointer-events: none;
}
.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}
