@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800&display=swap');

:root {
  --paper: #ffffff;
  --paper-2: #f7f7f7;
  --ink: #3c3c3c;
  --muted: #afafaf;
  --line: #e5e5e5;
  --accent: #58cc02;
  --accent-dark: #58a700;
  --accent-2: #1cb0f6;
  --accent-2-dark: #009ec9;
  --accent-soft: #d7ffb8;
  --danger: #ff4b4b;
  --shadow: 0 2px 8px rgba(0,0,0,.08);
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--paper-2);
  color: var(--ink);
  font-family: "Nunito", -apple-system, BlinkMacSystemFont, "Segoe UI",
               "Hiragino Sans", "Noto Sans JP", sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-right: 260px;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 24px 8px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: -.5px;
  line-height: 1;
  width: 44px;
  height: 44px;
  background: #7c3aed;
  border-radius: 14px;
  border-bottom: 3px solid #5b21b6;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #fff;
}
h1 {
  font-size: 24px;
  font-weight: 800;
  margin: 0;
  letter-spacing: -.02em;
  background: linear-gradient(135deg, #7c3aed 0%, #a855f7 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.subtitle { margin: 2px 0 0; color: var(--muted); font-size: 12px; font-weight: 600; }
.lang-toggle {
  border: 2px solid var(--line);
  border-bottom: 4px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  border-radius: 12px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.lang-toggle:hover { border-color: var(--accent); color: var(--accent-dark); }

/* ---------- reader ---------- */
main { flex: 1; }
.reader { max-width: 760px; margin: 8px auto 0; padding: 8px 24px 24px; }

.item {
  display: flex;
  gap: 14px;
  align-items: baseline;
  padding: 14px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background .15s, border-color .15s;
  border: 2px solid transparent;
  background: var(--paper);
  margin-bottom: 6px;
}
.item:hover { border-color: var(--line); }
.item .num {
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  min-width: 1.6em;
  text-align: right;
  user-select: none;
}
.lines { flex: 1; }
.ja {
  font-size: 16px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 4px;
  line-height: 1.5;
}
.en {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.5;
  font-family: "Nunito", Georgia, serif;
  transition: filter .2s, opacity .2s;
}

.item.current {
  background: #f2ffe8;
  border-color: #c8f09a;
  box-shadow: 0 2px 0 rgba(88,167,0,.08);
}
.item.current .num { color: var(--accent-dark); font-weight: 800; }
.item.playing-ja .ja { color: var(--accent-2); font-weight: 700; }
.item.playing-en .en { color: var(--accent-dark); }
.item.in-range { background: #f0fde4; border-color: #c6f08a; }

/* hide-answer */
.item.masked .en {
  filter: blur(7px);
  opacity: .45;
  user-select: none;
}
.item.masked .en:hover { filter: blur(3px); }

.item.is-a .num::after, .item.is-b .num::after {
  display: inline-block;
  margin-left: 6px;
  font-size: 10px;
  font-weight: 800;
  color: #fff;
  background: var(--accent);
  border-radius: 4px;
  padding: 1px 4px;
  vertical-align: middle;
}
.item.is-a .num::after { content: "A"; }
.item.is-b .num::after { content: "B"; }

/* ---------- memo button ---------- */
.memo-btn {
  flex: 0 0 auto;
  align-self: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid var(--line);
  border-bottom-width: 3px;
  background: var(--paper);
  color: var(--muted);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color .15s, background .15s, color .15s;
  flex-shrink: 0;
  margin-left: 4px;
}
.memo-btn:hover { border-color: #f59e0b; color: #d97706; }
.item.learned {
  background: #fffbf0;
  border-color: #fcd34d;
}
.item.learned .memo-btn {
  background: #f59e0b;
  border-color: #d97706;
  color: #fff;
}

/* ---------- tabs ---------- */
.tabs {
  display: flex;
  gap: 8px;
  max-width: 760px;
  margin: 6px auto 0;
  padding: 6px 24px 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 0 0 auto;
  border: 2px solid var(--line);
  border-bottom: 4px solid var(--line);
  background: var(--paper);
  color: var(--muted);
  border-radius: 12px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color .12s, color .12s, background .12s, transform .08s;
}
.tab:hover { border-color: var(--accent); color: var(--accent-dark); }
.tab:active { transform: translateY(2px); border-bottom-width: 2px; }
.tab.active {
  background: var(--accent);
  border-color: var(--accent-dark);
  border-bottom-color: var(--accent-dark);
  color: #fff;
}
.tab-n {
  font-size: 11px;
  opacity: .75;
  font-variant-numeric: tabular-nums;
  margin-left: 2px;
  font-weight: 700;
}
.tab.weak { border-style: dashed; border-bottom-style: solid; }
.tab.weak.active {
  background: var(--accent-2);
  border-color: var(--accent-2-dark);
  border-style: solid;
}

/* ---------- add form ---------- */
.adder { max-width: 760px; margin: 4px auto 0; padding: 8px 24px 24px; }
.cat-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.cat-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.cat-chip {
  border: 2px solid var(--line);
  border-bottom: 3px solid var(--line);
  background: var(--paper);
  color: var(--muted);
  border-radius: 10px;
  padding: 4px 12px;
  font-size: 12.5px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: border-color .12s, color .12s;
}
.cat-chip:hover { border-color: var(--accent); color: var(--accent-dark); }
.cat-chip.active {
  background: var(--accent-soft);
  border-color: var(--accent-dark);
  color: var(--accent-dark);
}
.adder-inner {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 14px;
  background: var(--paper);
  border: 2px dashed var(--line);
  border-radius: var(--radius);
}
.add-input {
  flex: 1 1 180px;
  min-width: 120px;
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 9px 11px;
  font-size: 14px;
  font-family: inherit;
  font-weight: 600;
  background: var(--paper-2);
  color: var(--ink);
}
.add-input.cat { flex: 0 1 150px; }
.add-input:focus { outline: none; border-color: var(--accent); background: var(--paper); }
.add-btn {
  flex: 0 0 auto;
  border: 2px solid var(--accent-dark);
  border-bottom: 4px solid var(--accent-dark);
  background: var(--accent);
  color: #fff;
  border-radius: 12px;
  padding: 9px 18px;
  font-size: 14px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: transform .08s, border-bottom-width .08s;
}
.add-btn:hover { filter: brightness(1.05); }
.add-btn:active { transform: translateY(2px); border-bottom-width: 2px; }
.add-btn:disabled { opacity: .6; cursor: default; }
.add-msg { flex: 1 1 100%; font-size: 12.5px; font-weight: 600; color: var(--accent-dark); min-height: 1em; }
.empty { color: var(--muted); padding: 24px; font-weight: 600; }

.bulk { margin-top: 10px; }
.bulk > summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent-2);
  list-style: none;
  user-select: none;
  padding: 4px 2px;
}
.bulk > summary::-webkit-details-marker { display: none; }
.bulk > summary::before { content: "▸ "; }
.bulk[open] > summary::before { content: "▾ "; }
.bulk-hint { font-size: 12px; font-weight: 600; color: var(--muted); margin: 6px 2px; line-height: 1.5; }
.bulk-text {
  width: 100%;
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13.5px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  background: var(--paper-2);
  color: var(--ink);
  resize: vertical;
  line-height: 1.5;
}
.bulk-text:focus { outline: none; border-color: var(--accent); }
.bulk-actions { display: flex; align-items: center; gap: 12px; margin-top: 8px; }

/* ---------- controls ---------- */
.controls {
  position: fixed;
  right: 0;
  top: 0;
  width: 260px;
  height: 100vh;
  background: var(--paper);
  border-left: 2px solid var(--line);
  box-shadow: -4px 0 16px rgba(0,0,0,.06);
  overflow-y: auto;
}
.controls-inner {
  width: 100%;
  padding: 20px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.transport {
  display: flex;
  justify-content: center;
  gap: 14px;
  padding-bottom: 14px;
  border-bottom: 2px solid var(--line);
}
.ctl {
  width: 46px; height: 46px;
  border-radius: 12px;
  border: 2px solid var(--line);
  border-bottom: 4px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  font-size: 17px;
  cursor: pointer;
  transition: transform .08s, border-bottom-width .08s, border-color .12s;
}
.ctl:hover { border-color: var(--accent); }
.ctl:active { transform: translateY(2px); border-bottom-width: 2px; }
.ctl.play {
  width: 58px; height: 58px;
  background: var(--accent);
  border-color: var(--accent-dark);
  border-bottom-color: var(--accent-dark);
  color: #fff;
  font-size: 20px;
  border-radius: 14px;
}
.ctl.play:active { transform: translateY(3px); }

.opts { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; flex-direction: column; align-items: flex-start; gap: 5px; }
.label { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.seg {
  display: inline-flex;
  background: var(--paper-2);
  border: 2px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}
.seg button {
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 12.5px;
  font-weight: 700;
  font-family: inherit;
  padding: 5px 10px;
  cursor: pointer;
  border-right: 1px solid var(--line);
  transition: background .1s, color .1s;
}
.seg button:last-child { border-right: 0; }
.seg button:hover { background: var(--accent-soft); color: var(--accent-dark); }
.seg button.active { background: var(--accent); color: #fff; }

.toggles { flex-direction: row; gap: 8px 14px; flex-wrap: wrap; }
.chk { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 700; cursor: pointer; }
.chk input { accent-color: var(--accent); }

.ab { flex-direction: row; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip {
  border: 2px solid var(--line);
  border-bottom: 3px solid var(--line);
  background: var(--paper-2);
  border-radius: 10px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: border-color .12s, transform .08s;
}
.chip:hover { border-color: var(--accent); }
.chip:active { transform: translateY(1px); border-bottom-width: 2px; }
.chip.ghost { color: var(--muted); }
.ab-ind { font-size: 12px; font-weight: 700; color: var(--accent-dark); font-variant-numeric: tabular-nums; }

/* ---------- footer ---------- */
.hints { text-align: center; color: var(--muted); font-size: 11.5px; font-weight: 600; padding: 12px; }

@media (max-width: 760px) {
  body {
    padding-right: 0;
    padding-bottom: calc(155px + env(safe-area-inset-bottom));
  }
  .controls {
    right: 0; left: 0; top: auto; bottom: 0;
    width: auto; height: auto;
    border-left: none; border-top: 2px solid var(--line);
    box-shadow: 0 -4px 16px rgba(0,0,0,.06);
    overflow-y: visible;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .controls-inner {
    padding: 6px 12px 6px;
    gap: 5px;
  }
  .transport { border-bottom: none; padding-bottom: 0; gap: 14px; }
  .ctl { width: 34px; height: 34px; font-size: 13px; border-bottom-width: 3px; border-radius: 10px; }
  .ctl.play { width: 42px; height: 42px; font-size: 16px; border-radius: 12px; }
  .opts { flex-direction: row; flex-wrap: wrap; gap: 4px 12px; justify-content: center; }
  .row { flex-direction: row; align-items: center; gap: 5px; }
  .label { font-size: 10px; white-space: nowrap; }
  .seg button { font-size: 11px; padding: 3px 7px; }
  .toggles { flex-direction: row; gap: 6px 10px; }
  .chk { font-size: 11px; gap: 4px; }
  .chip { font-size: 11px; padding: 3px 8px; }
  .ab-ind { font-size: 11px; }
  .ab { flex-direction: row; }
  .en { font-size: 18px; }
  .reader { padding: 4px 16px 20px; }
  .topbar { padding: 14px 16px 4px; }
  .tabs { padding: 4px 16px 0; }
}
