* { box-sizing: border-box; }

:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --ink: #24201b;
  --ink-soft: #6b6357;
  --accent: #c8443c;
  --accent-soft: #f4d9d6;
  --success: #3a7c3a;
  --success-soft: #dcead9;
  --highlight: #f7d84a;
  --highlight-border: #d4b41f;
  --border: #e6dfd3;
  --shadow: 0 1px 3px rgba(36, 32, 27, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17140f;
    --surface: #221e18;
    --ink: #f0ebe1;
    --ink-soft: #b3a99a;
    --accent: #e08079;
    --accent-soft: #3a2422;
    --success: #7cba7c;
    --success-soft: #22321f;
    --highlight: #6b5a1a;
    --highlight-border: #a68b2c;
    --border: #34302a;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  }
}

body {
  margin: 0;
  font-family: "Hiragino Sans", "Yu Gothic", "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
}

/* Locks the page in place while the paywall is blocking a gated tab, so the content
   behind it can't be scrolled past or around. */
body.no-scroll {
  overflow: hidden;
}

.app-header {
  padding: 20px 24px 0;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: relative;
  z-index: 600;
}

.app-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 14px;
}

.social-links {
  display: flex;
  gap: 10px;
}

.social-icon {
  color: var(--ink-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s;
}

.social-icon:hover {
  color: var(--accent);
}

.app-header h1 {
  margin: 0;
  font-size: 26px;
  display: flex;
  align-items: center;
  gap: 0;
}

.header-logo {
  height: 88px;
  width: auto;
  border-radius: 6px;
}


.lang-toggle {
  flex-shrink: 0;
}

.tabs {
  display: flex;
  gap: 4px;
}

.tab-btn {
  padding: 10px 18px;
  border: none;
  background: none;
  color: var(--ink-soft);
  font-size: 15px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}

.tab-btn:hover { color: var(--ink); }

.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 16px 64px;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.panel-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
  align-items: center;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.seg-btn {
  padding: 7px 14px;
  border: none;
  background: var(--surface);
  color: var(--ink-soft);
  cursor: pointer;
  font-size: 14px;
  border-right: 1px solid var(--border);
}

.seg-btn:last-child { border-right: none; }

.seg-btn.active {
  background: var(--accent);
  color: white;
}

#kanji-search {
  flex: 1;
  min-width: 220px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
}

/* Kana grid */
.kana-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 10px;
}

.kana-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 6px;
  text-align: center;
  box-shadow: var(--shadow);
}

.kana-char {
  font-size: 28px;
  line-height: 1.2;
}

.kana-romaji {
  margin-top: 4px;
  font-size: 13px;
  color: var(--ink-soft);
}

/* Kana romaji-typing practice: shuffled chart of blanks to fill in */
.kana-quiz-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.kana-quiz-score {
  color: var(--ink-soft);
  font-size: 14px;
  min-height: 1.2em;
}

.kana-quiz-actions {
  display: flex;
  gap: 8px;
}

.kana-quiz-blank {
  width: 100%;
  margin-top: 6px;
  padding: 5px 4px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--ink);
  font-size: 13px;
  text-align: center;
}

.kana-quiz-blank:focus {
  outline: none;
  border-color: var(--accent);
}

.kana-card.correct .kana-quiz-blank {
  border-color: var(--success);
  background: var(--success-soft);
  color: var(--success);
}

.kana-card.incorrect .kana-quiz-blank {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.kana-quiz-answer {
  margin-top: 4px;
  font-size: 12px;
  color: var(--accent);
}

.kana-quiz-history {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 18px;
}

.kana-quiz-history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.kana-quiz-history-header h4 {
  margin: 0;
  font-size: 15px;
}

.kana-quiz-history-clear-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 13px;
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
}

.kana-quiz-history-list {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 220px;
  overflow-y: auto;
}

.kana-quiz-history-item {
  font-size: 13px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.kana-quiz-history-item:last-child { border-bottom: none; }

.kana-quiz-history-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.kana-quiz-history-label { color: var(--ink); }
.kana-quiz-history-time { color: var(--ink-soft); font-size: 12px; display: block; }
.kana-quiz-history-score { font-weight: 600; white-space: nowrap; }

.kana-quiz-history-right {
  margin-top: 6px;
  font-size: 12px;
  color: var(--success);
  line-height: 1.5;
}

.kana-quiz-history-missed {
  margin-top: 4px;
  font-size: 12px;
  color: var(--accent);
  line-height: 1.5;
}

.kana-quiz-history-missed-clean { color: var(--success); }

.kana-quiz-history-empty {
  color: var(--ink-soft);
  font-size: 13px;
  margin-top: 10px;
}

.kana-quiz-history-note {
  color: var(--ink-soft);
  font-size: 12px;
  margin: 10px 0 0;
}

/* Vocab grid */
.vocab-count {
  color: var(--ink-soft);
  font-size: 13px;
  margin-bottom: 10px;
}

#vocab-category-select {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
}

.vocab-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
}

.vocab-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

.vocab-jp {
  font-size: 18px;
}

.vocab-romaji {
  color: var(--accent);
  font-size: 13px;
  margin-top: 3px;
}

.vocab-meaning {
  color: var(--ink-soft);
  font-size: 13px;
  margin-top: 3px;
}

.vocab-category-tag {
  display: inline-block;
  margin-top: 6px;
  font-size: 11px;
  color: var(--ink-soft);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 8px;
}

/* Kanji grid */
.kanji-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
}

.kanji-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  box-shadow: var(--shadow);
  cursor: pointer;
}

.kanji-card-top {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.kanji-char {
  font-size: 34px;
}

.kanji-meaning {
  color: var(--ink-soft);
  font-size: 14px;
}

.kanji-readings {
  margin-top: 8px;
  font-size: 13px;
  color: var(--ink-soft);
  line-height: 1.5;
}

.kanji-readings b {
  color: var(--ink);
  font-weight: 600;
}

.kanji-example {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
  display: none;
  font-size: 14px;
  line-height: 1.5;
}

.kanji-card.expanded .kanji-example { display: block; }

.kanji-example .jp { font-size: 15px; }
.kanji-example .romaji { color: var(--accent); font-size: 13px; margin-top: 2px; }
.kanji-example .meaning { color: var(--ink-soft); font-size: 13px; margin-top: 6px; }

/* Word-by-word segment alignment (Japanese word -> romaji) */
.segment-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 12px;
  margin: 4px 0;
}

.segment {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 28px;
}

.segment-jp {
  font-size: 16px;
  white-space: nowrap;
}

.segment-arrow {
  font-size: 10px;
  line-height: 1.2;
  color: var(--ink-soft);
  opacity: 0.6;
}

.segment-romaji {
  font-size: 12px;
  color: var(--accent);
  white-space: nowrap;
}

.segment-en {
  font-size: 11px;
  color: var(--ink-soft);
  font-style: italic;
  white-space: nowrap;
  max-width: 110px;
  text-align: center;
}

.letter-row {
  gap: 6px 4px;
  margin: 0;
}

.letter-segment .segment-jp {
  font-size: 15px;
}

.letter-segment .segment-romaji {
  font-size: 11px;
}

/* Groups a word's letter-by-letter chips with its own gloss underneath, so a full
   phrase reads as a row of word-groups (letters -> gloss) rather than flat chips. */
.phrase-word-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 14px;
}

.phrase-word-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4px 6px;
  border-radius: 8px;
}

.phrase-word-gloss {
  margin-top: 5px;
  font-size: 11px;
  color: var(--ink-soft);
  font-style: italic;
  text-align: center;
  max-width: 130px;
}

/* Scenarios */
.scenario-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}

.scenario-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.scenario-icon { font-size: 30px; }

.scenario-card h3 {
  margin: 10px 0 4px;
  font-size: 16px;
}

.scenario-card .jp {
  color: var(--ink-soft);
  font-size: 14px;
}

.hidden { display: none !important; }

.back-btn {
  border: none;
  background: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 14px;
  padding: 0 0 12px;
}

.scenario-desc {
  color: var(--ink-soft);
  margin-top: -6px;
}

.phrase-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
}

.phrase-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
}

.phrase-item .jp { font-size: 16px; }
.phrase-item .romaji { color: var(--accent); font-size: 13px; margin-top: 3px; }
.phrase-item .meaning { color: var(--ink-soft); font-size: 13px; margin-top: 6px; }

.primary-btn {
  background: var(--accent);
  color: white;
  border: none;
  padding: 10px 18px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
}

.secondary-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--ink);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
}

/* Translate */
.translate-textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: 15px;
  font-family: inherit;
  resize: vertical;
  margin-bottom: 12px;
}

.translate-result {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 16px;
}

.translate-result .phrase-item {
  margin: 0;
}

.translate-history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 28px;
  margin-bottom: 10px;
}

.translate-history-header h3 {
  margin: 0;
}

.translate-history {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-empty {
  color: var(--ink-soft);
  font-size: 14px;
}

.history-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
}

.history-item-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 6px 12px;
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px dashed var(--border);
}

.history-input {
  font-size: 14px;
  color: var(--ink);
  font-weight: 600;
}

.history-meta {
  font-size: 12px;
  color: var(--ink-soft);
}

/* Chat */
.chat-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.chat-controls select {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
}

.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 320px;
  max-height: 55vh;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  background: var(--surface);
  margin-bottom: 8px;
}

.chat-msg {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 10px;
  line-height: 1.5;
}

.chat-msg.user {
  align-self: flex-end;
  background: var(--accent-soft);
}

.chat-msg.assistant {
  align-self: flex-start;
  background: var(--bg);
  border: 1px solid var(--border);
}

.chat-msg .jp { font-size: 16px; }
.chat-msg .romaji { color: var(--accent); font-size: 13px; margin-top: 4px; }
.chat-msg .meaning { color: var(--ink-soft); font-size: 13px; margin-top: 4px; }

.chat-status {
  min-height: 18px;
  font-size: 13px;
  color: var(--ink-soft);
  margin-bottom: 8px;
}

.chat-input-row {
  display: flex;
  gap: 8px;
}

#chat-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
}

@media (max-width: 600px) {
  .app-header h1 { font-size: 22px; }
  .tabs { overflow-x: auto; }
}

/* Study ruler: floating drag-to-reveal cover, works over any tab */
.ruler-toggle-btn {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: white;
  font-size: 20px;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
  z-index: 1000;
}

/* Highlighter: floating toggle, stacked above the ruler button */
.highlight-toggle-btn {
  position: fixed;
  bottom: 78px;
  right: 20px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: var(--surface);
  color: var(--ink);
  font-size: 20px;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
  z-index: 1000;
}

.highlight-toggle-btn.active {
  background: var(--highlight);
  outline: 3px solid var(--highlight-border);
}

.kana-card.highlighted,
.kanji-card.highlighted,
.vocab-card.highlighted,
.phrase-item.highlighted {
  background: var(--highlight);
  border-color: var(--highlight-border);
}

.ruler-toggle-btn.active {
  outline: 3px solid var(--accent-soft);
}

/* top/height are fixed base values; dragging moves both via transform (compositor-only,
   no layout reflow) so it tracks touch input smoothly instead of feeling laggy. */
.ruler-cover {
  position: fixed;
  top: 44px;
  left: 0;
  right: 0;
  height: 60px;
  background: var(--bg);
  border-top: 2px dashed var(--accent);
  border-bottom: 2px dashed var(--accent);
  z-index: 900;
  pointer-events: none;
  will-change: transform;
}

.ruler-handle {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 44px;
  background: var(--accent);
  color: white;
  font-size: 12px;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: ns-resize;
  user-select: none;
  touch-action: none;
  z-index: 901;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  will-change: transform;
}

/* Paywall: dimmed backdrop over the whole app, content visible but not interactive */
.paywall-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

/* Vocab gives away too much for free even dimmed (502 readable words), so it gets a
   fully opaque backdrop instead of the semi-transparent one used on other gated tabs. */
.paywall-backdrop.paywall-opaque {
  background: var(--bg);
}

.paywall-modal {
  background: var(--surface);
  border-radius: 14px;
  padding: 32px 28px;
  max-width: 420px;
  width: 100%;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.paywall-modal h2 {
  margin: 0 0 10px;
  font-size: 22px;
}

.paywall-modal p {
  margin: 0 0 20px;
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.5;
}

.paywall-price {
  font-size: 28px;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 16px;
}

.paywall-price span {
  font-size: 14px;
  font-weight: 400;
  color: var(--ink-soft);
  margin-left: 4px;
}

.paywall-pay-btn {
  width: 100%;
  padding: 13px;
  font-size: 16px;
}

.link-btn {
  display: block;
  margin: 14px auto 0;
  background: none;
  border: none;
  color: var(--accent);
  font-size: 13px;
  cursor: pointer;
  text-decoration: underline;
}

/* Account tab */
.auth-form-note {
  font-size: 13px;
  color: var(--ink-soft);
  margin: -4px 0 12px;
}

.auth-forms {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  max-width: 600px;
}

.auth-form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
}

.auth-form-card h3 {
  margin: 0 0 12px;
}

.auth-form-card form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.auth-form-card input {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
}

#account-logged-in {
  max-width: 480px;
}

#account-logged-in p {
  font-size: 15px;
}

#account-premium-status {
  font-weight: 600;
}

#account-upgrade-btn {
  margin-right: 10px;
}

/* Landing page */
.landing-hero {
  text-align: center;
  padding: 32px 12px 44px;
  max-width: 580px;
  margin: 0 auto;
}

.hero-badge {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 999px;
  margin-bottom: 18px;
}

.landing-hero h2 {
  font-size: 34px;
  margin: 0 0 14px;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

.landing-hero p {
  color: var(--ink-soft);
  font-size: 16px;
  line-height: 1.6;
  margin: 0 0 24px;
}

.landing-cta {
  padding: 16px 40px;
  font-size: 16px;
  min-width: 320px;
}

.landing-section {
  margin: 48px 0;
}

.landing-section h3 {
  text-align: center;
  font-size: 22px;
  margin: 0 0 24px;
}

.landing-compare {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
  max-width: 800px;
  margin: 0 auto;
}

.compare-card {
  border-radius: 12px;
  padding: 22px;
  border: 1px solid var(--border);
  text-align: center;
}

.compare-card h4 {
  margin: 0 0 14px;
  text-align: center;
}

.compare-others {
  background: var(--surface);
  opacity: 0.75;
}

.compare-us {
  background: var(--surface);
  border: 2px solid var(--accent);
}

.jp-sample {
  font-size: 20px;
  text-align: center;
  margin: 0;
}

.compare-arrow {
  text-align: center;
  color: var(--ink-soft);
  margin: 6px 0;
}

.compare-note {
  color: var(--ink-soft);
  font-size: 13px;
  margin: 14px 0 0;
  line-height: 1.5;
}

.compare-segments {
  justify-content: center;
  margin: 8px 0;
}

.landing-features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 18px;
  max-width: 960px;
  margin: 0 auto;
}

.feature-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 22px;
  transition: transform 0.15s, box-shadow 0.15s;
}

.feature-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.feature-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--accent-soft);
  font-size: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 14px;
}

.feature-card h4 {
  margin: 0 0 8px;
  font-size: 16px;
}

.feature-card p {
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.55;
  margin: 0;
}

.testimonials-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
  max-width: 1000px;
  margin: 0 auto;
}

.testimonial-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
}

.testimonial-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.testimonial-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}

.testimonial-name {
  font-weight: 600;
  font-size: 14px;
}

.testimonial-stars {
  color: var(--accent);
  font-size: 12px;
}

.testimonial-quote {
  font-size: 13px;
  color: var(--ink-soft);
  line-height: 1.55;
  margin: 0;
}
