:root {
  --primary: #344e41;
  --bg-deep: #05161c;
  --bg-mid: #0a2e38;
  --accent: #bc6c25;
  --secondary: #a3b18a;
  --card-glass: rgba(255, 255, 255, 0.96);
  --ios-glass: rgba(255, 255, 255, 0.12);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  padding: 0 8px 150px;
  min-height: 100vh;
  color: #fff;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", sans-serif;
  background: radial-gradient(circle at center, var(--bg-mid) 0%, var(--bg-deep) 100%);
  overflow-x: hidden;
}
.header {
  position: sticky;
  top: 0;
  z-index: 30;
  height: 52px;
  margin: 0 -8px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--ios-glass);
  backdrop-filter: blur(36px) saturate(200%);
  border-bottom: 1px solid rgba(255,255,255,0.15);
}
.header-left { display: flex; gap: 8px; align-items: center; }
.app-title { color: #fff; text-decoration: none; font-weight: 900; letter-spacing: 0.2px; }
.app-title small { margin-left: 4px; opacity: 0.6; font-size: 0.75em; }
.status-dot {
  width: 9px; height: 9px; border-radius: 50%; border: none;
  background: #6b7280; box-shadow: 0 0 0 transparent;
}
.status-dot.active { background: #4ade80; box-shadow: 0 0 8px #4ade80; }
.header-right {
  border: none; background: transparent; color: #fff;
  display: flex; align-items: center; gap: 10px;
}
.progress-segments { display: flex; gap: 2px; }
.segment { width: 4.5px; height: 16px; border-radius: 1px; background: rgba(255,255,255,0.15); }
.segment.filled { background: #4ade80; box-shadow: 0 0 6px #4ade80; }
.stats-text-block { text-align: right; }
.percent-text { font-size: 1.25rem; font-weight: 900; line-height: 1; }
.count-text { font-size: 0.7rem; opacity: 0.72; }

.lib-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}
.tab-btn {
  border: 1px solid rgba(255,255,255,0.18); border-radius: 999px;
  background: rgba(255,255,255,0.06); color: #d7e6e2;
  font-size: 0.74rem; padding: 6px 8px;
}
.tab-btn.active {
  background: rgba(163, 177, 138, 0.28);
  color: #fff; border-color: rgba(163, 177, 138, 0.5);
}

.main-content {
  margin-top: 12px;
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(4, minmax(0, 1fr));
  min-height: 520px;
}
.word-card {
  min-height: 0; background: var(--card-glass); color: #111;
  border-left: 4px solid var(--primary); border-radius: 16px; padding: 12px 10px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25); position: relative; overflow: hidden;
  transition: transform 0.2s ease, opacity 0.2s ease;
}
.card-sway {
  animation: cardSway 0.95s ease-in-out both;
}
@keyframes cardSway {
  0% { transform: translate3d(0,0,0) rotate(0deg); }
  25% { transform: translate3d(4px,-6px,0) rotate(-1.6deg); }
  50% { transform: translate3d(-5px,5px,0) rotate(1.2deg); }
  75% { transform: translate3d(6px,-3px,0) rotate(-1deg); }
  100% { transform: translate3d(0,0,0) rotate(0deg); }
}
.card-dismissing {
  opacity: 0;
  transform: scale(0.92) translateX(28px);
}
.placeholder-card {
  border-left-color: rgba(52, 78, 65, 0.45);
  background: rgba(255, 255, 255, 0.78);
}
.ph-line {
  height: 12px;
  border-radius: 8px;
  background: linear-gradient(90deg, rgba(148,163,184,0.26), rgba(226,232,240,0.7), rgba(148,163,184,0.26));
  background-size: 180% 100%;
  animation: phMove 1.2s infinite linear;
  margin-top: 10px;
}
.ph-1 { width: 72%; margin-top: 26px; }
.ph-2 { width: 48%; }
.ph-3 { width: 64%; }
@keyframes phMove {
  from { background-position: 180% 0; }
  to { background-position: -20% 0; }
}
.card-title-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.bubble-btn {
  width: 20px; height: 20px; border: none; border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #fff, #d1e8f4, #7b68ee);
  flex: 0 0 auto;
}
.pop-particle {
  position: fixed;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  pointer-events: none;
  z-index: 10000;
  background: rgba(255,255,255,0.95);
  box-shadow: 0 0 8px rgba(255,255,255,0.8);
  animation: particleExplode 0.45s ease-out forwards;
}
@keyframes particleExplode {
  from { transform: translate(0, 0) scale(1); opacity: 1; }
  to { transform: translate(var(--dx), var(--dy)) scale(0.2); opacity: 0; }
}
.ai-btn {
  border: none;
  background: transparent;
  color: #475569;
  font-size: 18px;
  line-height: 1;
  padding: 0;
  flex: 0 0 auto;
}
.fish-fallback {
  width: 100%;
  height: 100%;
  align-items: center;
  justify-content: center;
  font-size: 44px;
  filter: drop-shadow(0 10px 14px rgba(0,0,0,0.35));
}
.kanji {
  margin-top: 0;
  color: var(--primary);
  font-size: clamp(15px, 4vw, 27px);
  font-weight: 900;
  line-height: 1.1;
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.reading { margin-top: 4px; color: var(--accent); font-size: clamp(11px, 3vw, 16px); font-weight: 800; }
.kanji[data-action="speak-word"], .reading[data-action="speak-word"] { cursor: pointer; }
.pressable-title {
  transition: transform 0.14s ease-out, opacity 0.14s ease-out;
  transform: translate3d(0, 0, 0);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
.pressable-title.is-pressed {
  transform: translate3d(0, 3px, 0) scale(0.975);
  opacity: 0.88;
}
.pressable-title:active {
  transform: translate3d(0, 3px, 0) scale(0.975);
  opacity: 0.88;
}
.meaning { margin-top: 2px; color: #1f2937; font-size: clamp(12px, 3.3vw, 18px); }
.example-box {
  margin-top: 8px; padding-top: 8px; border-top: 1px dashed rgba(0,0,0,0.12);
  font-size: 0.8rem; color: #334155;
}
.example-item { margin-top: 6px; }
.example-line {
  display: flex;
  align-items: baseline;
  gap: 6px;
  flex-wrap: nowrap;
}
.example-line .jp {
  flex: 0 1 auto;
  min-width: 0;
}
.example-icon-btn {
  border: none;
  background: transparent;
  color: #334155;
  padding: 0 2px;
  line-height: 1;
  font-size: 12px;
  cursor: pointer;
}
.zh-line {
  display: block;
  margin-top: 2px;
}
.example-box ruby rt {
  font-size: 0.62em;
  color: #64748b;
}
.srs-badge { position: absolute; bottom: 5px; right: 8px; font-size: 10px; color: #64748b; }

.custom-import-panel {
  margin-top: 10px; padding: 12px; border-radius: 14px;
  background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.12);
}
.custom-import-panel p { margin: 0 0 10px; font-size: 12px; opacity: 0.85; }
.import-grid { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; }
.import-row { margin-top: 8px; display: grid; grid-template-columns: auto 1fr; gap: 8px; }
textarea, input[type="text"], input[type="search"] {
  width: 100%; border-radius: 10px; border: 1px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.12); color: #fff; padding: 10px; outline: none;
}
textarea::placeholder, input::placeholder { color: rgba(255,255,255,0.65); }
.btn-primary {
  border: none; border-radius: 10px; padding: 10px 12px;
  color: #102a2f; font-weight: 700; background: #a3b18a;
}
.muted { opacity: 0.8; font-size: 12px; }

.persistence-panel {
  position: fixed;
  left: 50%;
  bottom: calc(10px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 35;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: min(92vw, 860px);
  padding: 10px 10px 16px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(24px) saturate(160%);
  box-shadow: 0 10px 30px rgba(0,0,0,0.34);
}
.bottom-tabs .tab-btn {
  background: rgba(10, 22, 30, 0.34);
}
.dock-actions {
  display: flex;
  justify-content: center;
  gap: 44px;
  width: 100%;
}
.dock-btn {
  width: 34px;
  height: 34px;
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 999px;
  background: rgba(9, 24, 34, 0.35);
  color: #e2edf3;
}
.dock-btn svg {
  width: 78%;
  height: 78%;
  margin: 11%;
}

.overlay {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(5, 22, 28, 0.95); backdrop-filter: blur(14px);
}
.hidden { display: none !important; }
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px; border-bottom: 1px solid rgba(255,255,255,0.12);
}
.close-btn { border: none; background: none; color: #fff; font-size: 34px; }
.modal-body {
  padding: 12px;
  max-height: calc(100vh - 74px);
  overflow: auto;
}

.account-panel {
  margin-bottom: 10px;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 12px;
  padding: 10px;
}
.account-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}
.account-status {
  font-size: 12px;
  color: #a3e635;
}
.account-uid {
  font-size: 12px;
  opacity: 0.8;
  margin-bottom: 8px;
}
.account-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.account-actions {
  margin-top: 8px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}
.account-actions button {
  border: none;
  border-radius: 8px;
  padding: 8px;
  background: rgba(255,255,255,0.16);
  color: #fff;
}

.manager-toolbar {
  display: grid; grid-template-columns: 1fr auto auto auto;
  gap: 8px; margin-bottom: 8px;
}
.manager-toolbar button {
  border: none; border-radius: 10px; padding: 10px;
  color: #fff; background: rgba(255,255,255,0.15);
}
.manager-toolbar .danger, .danger { background: #ef476f; color: #fff; }
#fullListContainer { max-height: 44vh; overflow: auto; border-radius: 10px; }
#confirmImportBtn {
  margin: 8px 0 10px;
  width: 100%;
}
.list-row {
  background: rgba(255,255,255,0.12); border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px; padding: 8px; margin-bottom: 6px;
  display: grid; grid-template-columns: 1fr auto; gap: 8px;
}
.list-row.done { opacity: 0.5; }
.list-meta { font-size: 11px; opacity: 0.76; }

.confirm-toast {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: min(86vw, 320px); z-index: 70; border-radius: 16px; padding: 16px;
  border: 1px solid rgba(163,177,138,0.8); background: rgba(10,46,56,0.98);
}
.confirm-actions { margin-top: 10px; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.confirm-actions button { border: none; border-radius: 10px; padding: 10px; background: rgba(255,255,255,0.16); color: #fff; }
.confirm-progress { margin-top: 10px; width: 100%; height: 4px; background: #4ade80; transform-origin: left center; }

.status-line {
  width: 100%;
  text-align: center;
  min-height: 16px;
  padding-top: 2px;
  text-align: center;
  font-size: 11px;
  color: rgba(230,243,249,0.88);
  pointer-events: auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.status-line a { color: #8ab4f8; }

.import-toast {
  position: fixed;
  left: 50%;
  top: 78px;
  transform: translateX(-50%);
  z-index: 80;
  max-width: min(92vw, 520px);
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.24);
  background: rgba(7, 22, 30, 0.84);
  color: #e6f3f9;
  font-size: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  backdrop-filter: blur(10px) saturate(140%);
}

.bg-bubbles {
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
}
.bg-bubble {
  position: absolute; bottom: -60px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, rgba(255,255,255,0.14), transparent);
  animation: rise linear infinite;
}
@keyframes rise {
  0% { transform: translateY(0); opacity: 0; }
  10% { opacity: 0.7; }
  100% { transform: translateY(-110vh); opacity: 0; }
}

@media (max-width: 520px) {
  .import-grid { grid-template-columns: 1fr; }
  .import-row { grid-template-columns: 1fr; }
  .account-grid { grid-template-columns: 1fr; }
  .account-actions { grid-template-columns: 1fr; }
  .kanji { font-size: clamp(14px, 5vw, 23px); }
}
@media (min-width: 820px) {
  body { max-width: 860px; margin: 0 auto; }
}
