:root {
  --bg: #f7f5f2;
  --surface: #ffffff;
  --text: #1c1c1e;
  --muted: #6b6b70;
  --accent: #bc002d;
  --border: #e4e0da;
  --shadow: 0 2px 10px rgba(0,0,0,0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121214;
    --surface: #1d1d20;
    --text: #f2f1ee;
    --muted: #9a9a9f;
    --accent: #ff5a72;
    --border: #2c2c30;
    --shadow: 0 2px 10px rgba(0,0,0,0.4);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  padding-bottom: env(safe-area-inset-bottom);
}

header {
  padding: 16px 20px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

header h1 {
  font-size: 18px;
  margin: 0;
  font-weight: 600;
}

header .count {
  font-size: 13px;
  color: var(--muted);
}

main {
  flex: 1;
  overflow-y: auto;
  padding: 8px 20px 20px;
}

.view { display: none; }
.view.active { display: block; height: 100%; }

/* Cards view */
.card-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 20px;
}

.card {
  width: 100%;
  min-height: 220px;
  background: var(--surface);
  border-radius: 20px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 28px;
  font-size: 24px;
  line-height: 1.5;
  cursor: pointer;
  user-select: none;
  border: 1px solid var(--border);
}

.card .lang-tag {
  position: absolute;
  margin-top: -170px;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.card-wrap { position: relative; width: 100%; }

.controls-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

button.icon-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow);
}

button.icon-btn:active { transform: scale(0.94); }

button.icon-btn.primary {
  background: var(--accent);
  color: white;
  border: none;
}

.mode-toggle {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 12px;
}

.mode-toggle button {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
}

.mode-toggle button.active {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

/* Library view */
.lib-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 16px;
}

.lib-section h2 {
  font-size: 14px;
  margin: 0 0 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.field {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  margin-bottom: 8px;
}

textarea.field { min-height: 90px; resize: vertical; font-family: inherit; }

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

.btn.secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

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

.sentence-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.sentence-item:last-child { border-bottom: none; }

.sentence-item .txt .en { font-size: 14px; color: var(--muted); }
.sentence-item .txt .jp { font-size: 16px; margin-top: 2px; }

.sentence-item .del {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
}

nav.tabbar {
  display: flex;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

nav.tabbar button {
  flex: 1;
  border: none;
  background: none;
  color: var(--muted);
  padding: 12px 0 calc(10px + env(safe-area-inset-bottom));
  font-size: 13px;
  cursor: pointer;
}

nav.tabbar button.active { color: var(--accent); font-weight: 600; }

.hint {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.toast.show { opacity: 1; }
