:root {
  --bg-0: #101019;
  --bg-1: #1a1b26;
  --bg-2: #21222f;
  --surface: #ffffff;
  --border: #2e3040;
  --border-light: #e5e7eb;
  --text: #f2f2f7;
  --text-ink: #1f2430;
  --muted: #9599ad;
  --muted-ink: #7a8194;
  --accent-1: #ff9966;
  --accent-2: #ff5f7e;
  --accent-grad: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  --accent-glow: rgba(255, 122, 105, 0.35);
  --person: #5b9dff;
  --place: #35c98d;
  --org: #b48bff;
  --number: #ffb020;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background:
    radial-gradient(1100px 520px at 12% -10%, rgba(255, 122, 105, 0.16), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(91, 157, 255, 0.10), transparent 55%),
    var(--bg-0);
  color: var(--text);
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Noto Sans JP", sans-serif;
}
button { font-family: inherit; }

.view[hidden] { display: none !important; }

/* ===== Paste screen ===== */
#view-paste {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.paste-card {
  width: 100%;
  max-width: 640px;
  text-align: center;
}
.paste-card h1 {
  font-size: 2.2rem;
  margin: 0 0 8px;
  letter-spacing: -0.01em;
  background: linear-gradient(135deg, #fff 30%, var(--accent-1));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.paste-sub {
  color: var(--muted);
  margin: 0 0 28px;
  font-size: 1rem;
}
.paste-card textarea {
  width: 100%;
  padding: 16px 18px;
  border: 1px solid var(--border-light);
  border-radius: 14px;
  font-size: 1.05rem;
  font-family: inherit;
  resize: vertical;
  background: var(--surface);
  color: var(--text-ink);
  box-shadow: 0 20px 45px -20px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.02);
}
.paste-samples {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin: 14px 0 22px;
}
.sample {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.82rem;
  cursor: pointer;
  color: var(--text);
}
.sample { transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease; }
.sample:hover { background: #2a2c3c; border-color: var(--accent-1); transform: translateY(-1px); }
.sample:active { transform: translateY(0) scale(0.96); }

.primary-btn {
  background: var(--accent-grad);
  color: #2a1608;
  border: none;
  border-radius: 10px;
  padding: 12px 30px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 12px 30px -10px var(--accent-glow);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.primary-btn:hover { transform: translateY(-1px); box-shadow: 0 16px 36px -10px var(--accent-glow); }
.primary-btn:active { transform: translateY(0) scale(0.97); }
.primary-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; box-shadow: none; }
.paste-status { margin-top: 12px; font-size: 0.85rem; color: var(--muted); min-height: 1.2em; }

/* ===== Reader screen ===== */
#view-reader { min-height: 100vh; padding-bottom: 40px; }
.reader-topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(16, 16, 25, 0.85);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar-spacer { flex: 1; }
.icon-btn {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 0.85rem;
  color: var(--text);
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}
.icon-btn:hover { background: #2a2c3c; border-color: var(--accent-1); }
.icon-btn:active { transform: scale(0.94); }

.popover {
  position: absolute;
  right: 16px;
  top: 56px;
  z-index: 20;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 20px 45px -15px rgba(0, 0, 0, 0.6);
  padding: 16px;
  width: 280px;
  max-width: calc(100vw - 32px);
  color: var(--text);
  opacity: 0;
  transform-origin: top right;
  transform: translateY(-6px) scale(0.96);
  transition: opacity 0.16s ease, transform 0.16s ease;
}
.popover.show { opacity: 1; transform: translateY(0) scale(1); }
.popover .opt { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; margin-bottom: 10px; cursor: pointer; }
.popover h3 { margin: 0 0 10px; font-size: 0.95rem; }
.watermark-input {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
  background: var(--bg-2);
  color: var(--text);
}
.watermark-input:disabled { opacity: 0.5; }

.vocab-list { max-height: 320px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.vocab-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.85rem;
  background: var(--bg-2);
}
.vocab-word { font-weight: 600; margin-right: 6px; }
.vocab-reading { color: var(--muted); font-size: 0.8rem; }
.vocab-meaning { color: var(--muted); font-size: 0.78rem; margin-top: 2px; max-width: 180px; }
.vocab-row .icon-btn { font-size: 0.75rem; padding: 4px 8px; flex-shrink: 0; }
.vocab-empty { color: var(--muted); font-size: 0.85rem; }

.reader-wrap {
  position: relative;
  max-width: 760px;
  margin: 32px auto 0;
  padding: 44px 32px 32px;
  overflow: hidden;
  background: var(--surface);
  border-radius: 22px;
  box-shadow: 0 30px 80px -30px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(255, 255, 255, 0.04), 0 0 60px -20px var(--accent-glow);
}
.avatar {
  position: absolute;
  top: 8px;
  right: 24px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  box-shadow: 0 1px 4px rgba(0,0,0,0.15);
}
.watermark-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  flex-wrap: wrap;
  align-content: space-around;
  justify-content: space-around;
  transform: rotate(-24deg) scale(1.3);
  opacity: 0.12;
}
.watermark-layer span { font-size: 1.1rem; color: #000; white-space: nowrap; margin: 14px 18px; }

.reader-text {
  font-size: 1.55rem;
  line-height: 3;
  word-break: break-word;
  color: var(--text-ink);
}
.reader-text ruby { ruby-position: over; }
.reader-text rt {
  font-size: 0.42em;
  color: #a3a8ba;
  user-select: none;
  font-weight: normal;
}

.chunk {
  cursor: pointer;
  border-radius: 4px;
  padding: 0 1px;
  transition: background-color 0.15s ease, transform 0.1s ease;
}
.chunk:hover, .chunk:focus { background: rgba(255, 122, 105, 0.12); outline: none; }
.chunk:active { transform: scale(0.94); }
.chunk.segmented { background: rgba(31, 36, 48, 0.035); margin: 0 1px; }
.chunk.cat-person { box-shadow: inset 0 -2px 0 rgba(37, 99, 235, 0.4); }
.chunk.cat-place { box-shadow: inset 0 -2px 0 rgba(22, 163, 74, 0.4); }
.chunk.cat-number { box-shadow: inset 0 -2px 0 rgba(234, 138, 12, 0.45); }
.chunk.cat-particle, .chunk.cat-aux { box-shadow: inset 0 -1px 0 rgba(122, 129, 148, 0.4); }

/* ===== Raw morphological detail (collapsed by default) ===== */
.raw-details {
  max-width: 760px;
  margin: 12px auto 0;
  padding: 0 24px;
  color: var(--text);
}
.raw-details summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.85rem;
  padding: 8px 0;
  user-select: none;
}
.raw-details summary:hover { color: var(--text); }
.table-wrap { overflow-x: auto; margin-top: 8px; }
table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
th, td { text-align: left; padding: 5px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; }

/* ===== Word card (bottom sheet) ===== */
.card-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 9, 14, 0.55);
  backdrop-filter: blur(2px);
  z-index: 30;
  opacity: 0;
  transition: opacity 0.22s ease;
}
.card-overlay.show { opacity: 1; }

/* Mobile: bottom sheet that slides up. Desktop: centered dialog that pops in
   (anchoring it to the viewport bottom on a tall screen left a huge dead gap
   under the reading card -- a real modal reads better once there's room). */
.word-card {
  position: fixed;
  left: 50%;
  bottom: 0;
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  color: var(--text-ink);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -20px 60px -15px rgba(0, 0, 0, 0.5), 0 0 70px -20px var(--accent-glow);
  padding: 20px 22px 24px;
  z-index: 31;
  opacity: 0;
  transform: translate(-50%, 24px);
  transition: opacity 0.24s cubic-bezier(0.22, 0.9, 0.32, 1.2), transform 0.28s cubic-bezier(0.22, 0.9, 0.32, 1.2);
}
.word-card.show { opacity: 1; transform: translate(-50%, 0); }
@media (min-width: 540px) {
  .word-card {
    bottom: auto;
    top: 50%;
    border-radius: 20px;
    transform: translate(-50%, calc(-50% + 10px)) scale(0.96);
  }
  .word-card.show { transform: translate(-50%, -50%) scale(1); }
}
.word-card-head { display: flex; align-items: flex-start; justify-content: space-between; }
.card-word { font-size: 1.5rem; font-weight: 700; margin-right: 10px; }
.card-reading { color: var(--muted-ink); font-size: 1rem; }
.word-card .icon-btn { background: #f1f2f6; border-color: var(--border-light); color: var(--text-ink); transition: transform 0.15s ease, background 0.15s ease; }
.word-card .icon-btn:hover { background: #e7e9f0; border-color: var(--accent-1); }
#cardClose:hover { transform: rotate(90deg); }
.card-badges { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.badge {
  display: inline-block;
  background: var(--accent-grad);
  color: #3a1608;
  font-weight: 700;
  border-radius: 999px;
  padding: 3px 12px;
  font-size: 0.72rem;
  box-shadow: 0 6px 16px -8px var(--accent-glow);
  animation: badge-pop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
@keyframes badge-pop {
  from { opacity: 0; transform: scale(0.6); }
  to { opacity: 1; transform: scale(1); }
}
.card-meaning { font-size: 0.95rem; line-height: 1.6; min-height: 1.4em; }
.card-meaning .sense { margin-bottom: 6px; }
.card-meaning .sense-pos { color: var(--muted-ink); font-size: 0.75rem; margin-right: 6px; }
.card-grammar p { font-size: 0.88rem; line-height: 1.6; color: #3a4256; margin: 6px 0 0; }
.word-card-actions { display: flex; gap: 8px; margin-top: 16px; }
.chip-btn {
  border: 1px solid var(--border-light);
  background: #fff;
  color: var(--text-ink);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}
.chip-btn:hover { background: #f1f2f6; border-color: var(--accent-1); transform: translateY(-1px); }
.chip-btn:active { transform: translateY(0) scale(0.96); }
.chip-btn.saved {
  background: var(--accent-grad);
  color: #3a1608;
  border-color: transparent;
  font-weight: 700;
}
.chip-btn.bounce { animation: chip-bounce 0.35s cubic-bezier(0.34, 1.56, 0.64, 1); }
@keyframes chip-bounce {
  0% { transform: scale(1); }
  40% { transform: scale(1.16); }
  70% { transform: scale(0.94); }
  100% { transform: scale(1); }
}
