/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --mint: #CDECE6;
  --mint-dark: #8DB5AD;
  --mint-light: #E8F7F4;
  --pink: #FFD0E0;
  --pink-dark: #F0A0BB;
  --lavender: #EDE2FB;
  --orange: #FFE3B5;
  --text: #4A4A4A;
  --text-sub: #8A8A8A;
  --bg: #FAFCFC;
  --card: #FFFFFF;
  --border: #E6E9EC;
  --shadow: 0 2px 12px rgba(0,0,0,0.07);
  --shadow-md: 0 4px 20px rgba(0,0,0,0.10);
  --radius: 14px;
  --radius-lg: 20px;
  --font-jp: 'M PLUS Rounded 1c', 'Hiragino Maru Gothic Pro', sans-serif;
  --font-en: 'Nunito', sans-serif;
  --nav-height: 72px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-jp);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  max-width: 430px;
  margin: 0 auto;
  position: relative;
  overflow-x: hidden;
}
a { text-decoration: none; color: inherit; }
button { font-family: var(--font-jp); cursor: pointer; border: none; background: none; }
img { max-width: 100%; }

/* ===== APP CONTAINER ===== */
#app {
  min-height: 100vh;
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom));
}

/* ===== BOTTOM NAV ===== */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 430px;
  height: calc(var(--nav-height) + var(--safe-bottom));
  background: var(--card);
  border-top: 1.5px solid var(--border);
  display: flex;
  align-items: flex-start;
  justify-content: space-around;
  padding: 10px 0 var(--safe-bottom);
  z-index: 100;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  color: var(--text-sub);
  font-size: 10px;
  font-weight: 500;
  transition: color 0.2s;
  padding: 2px 0;
}
.nav-item svg { width: 24px; height: 24px; }
.nav-item.active { color: var(--mint-dark); }
.nav-item.active svg { filter: drop-shadow(0 0 4px rgba(141,181,173,0.5)); }

/* ===== PAGE TRANSITIONS ===== */
.page { animation: fadeIn 0.2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

/* ===== COMMON HEADER ===== */
.page-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(250,252,252,0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1.5px solid var(--border);
  padding: 12px 16px;
}
.page-header-inner {
  display: flex;
  align-items: center;
  gap: 10px;
}
.back-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--mint-light);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--mint-dark);
  font-size: 18px;
  flex-shrink: 0;
  transition: background 0.2s;
}
.back-btn:active { background: var(--mint); }
.page-header h1 {
  font-size: 18px;
  font-weight: 800;
  flex: 1;
}

/* ===== SEARCH BAR ===== */
.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
}
.search-input-wrap {
  position: relative;
  flex: 1;
}
.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-sub);
  pointer-events: none;
}
.search-icon svg { width: 18px; height: 18px; }
.search-input {
  width: 100%;
  height: 44px;
  border: 1.5px solid var(--border);
  border-radius: 22px;
  padding: 0 16px 0 40px;
  font-size: 15px;
  font-family: var(--font-jp);
  background: var(--card);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}
.search-input:focus { border-color: var(--mint-dark); }
.search-input::placeholder { color: var(--text-sub); }
.search-cancel-btn {
  color: var(--mint-dark);
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  padding: 8px 4px;
}
.search-clear-btn {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--text-sub);
  color: white;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ===== CATEGORY BADGE ===== */
.cat-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
}
.cat-spine    { background: #E8F7F4; color: #5BA89E; }
.cat-joint    { background: #FFF0F5; color: #D08098; }
.cat-tools    { background: #F0EFFF; color: #8880CC; }
.cat-drugs    { background: #FFF5E6; color: #CC9040; }
.cat-abbr     { background: #F5EEFF; color: #9970CC; }
.cat-monitor  { background: #E8F4FF; color: #5090CC; }

/* ===== STAR BUTTON ===== */
.star-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: transform 0.2s;
  flex-shrink: 0;
}
.star-btn:active { transform: scale(1.3); }
.star-btn svg { width: 22px; height: 22px; }
.star-btn.active svg { fill: #F5A623; stroke: #F5A623; }
.star-btn:not(.active) svg { fill: none; stroke: var(--text-sub); }

/* ===== TERM CARD ===== */
.term-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1.5px solid var(--border);
  transition: transform 0.15s, box-shadow 0.15s;
}
.term-card:active { transform: scale(0.98); box-shadow: none; }
.term-card-body { flex: 1; min-width: 0; }
.term-card-name { font-size: 15px; font-weight: 700; color: var(--text); }
.term-card-kana { font-size: 12px; color: var(--text-sub); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.term-card-abbr { font-family: var(--font-en); font-size: 11px; font-weight: 700; color: var(--mint-dark); margin-top: 2px; }

/* ===== HOME PAGE ===== */
.home-header {
  background: linear-gradient(160deg, var(--mint) 0%, var(--mint-light) 50%, var(--bg) 100%);
  padding: 52px 20px 20px;
  position: relative;
  overflow: hidden;
}
.home-header-top { display: flex; align-items: flex-end; justify-content: space-between; }
.home-title-area {}
.home-label { font-size: 11px; font-weight: 700; color: var(--mint-dark); letter-spacing: 1px; text-transform: uppercase; margin-bottom: 4px; }
.home-title { font-size: 22px; font-weight: 800; color: var(--text); line-height: 1.2; }
.home-cat { width: 100px; height: 100px; object-fit: contain; flex-shrink: 0; }
.home-search { margin-top: 14px; }
.home-content { padding: 0 16px 24px; }

/* ===== SECTION ===== */
.section { margin-top: 24px; }
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.section-title { font-size: 13px; font-weight: 800; color: var(--text-sub); display: flex; align-items: center; gap: 6px; }
.section-more { font-size: 12px; font-weight: 700; color: var(--mint-dark); background: var(--mint-light); padding: 5px 12px; border-radius: 20px; }

/* ===== CATEGORY GRID ===== */
.cat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.cat-tile {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 8px 12px;
  text-align: center;
  box-shadow: var(--shadow);
  border: 1.5px solid var(--border);
  transition: transform 0.15s;
  cursor: pointer;
}
.cat-tile:active { transform: scale(0.96); }
.cat-tile-icon { width: 48px; height: 48px; margin: 0 auto 8px; display: block; }
.cat-tile-label { font-size: 12px; font-weight: 700; color: var(--text); }
.cat-tile-count { font-size: 11px; color: var(--text-sub); margin-top: 2px; }

/* ===== RECENT SCROLL ===== */
.recent-scroll { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.recent-scroll::-webkit-scrollbar { display: none; }
.recent-card {
  flex-shrink: 0;
  width: 130px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow);
  border: 1.5px solid var(--border);
  cursor: pointer;
  transition: transform 0.15s;
}
.recent-card:active { transform: scale(0.96); }
.recent-card-name { font-size: 13px; font-weight: 700; color: var(--text); margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recent-card-kana { font-size: 10px; color: var(--text-sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recent-card-abbr { font-family: var(--font-en); font-size: 11px; color: var(--mint-dark); font-weight: 700; margin-top: 4px; }

/* ===== FAVORITES LIST ===== */
.fav-list { display: flex; flex-direction: column; gap: 8px; }
.fav-item {
  background: var(--card);
  border-radius: var(--radius);
  padding: 12px 16px;
  box-shadow: var(--shadow);
  border: 1.5px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  transition: transform 0.15s;
}
.fav-item:active { transform: scale(0.98); }
.fav-item-left { flex: 1; min-width: 0; }
.fav-item-name { font-size: 14px; font-weight: 700; }
.fav-item-sub { font-size: 11px; color: var(--text-sub); margin-top: 2px; }

/* ===== EMPTY STATE ===== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 48px 20px;
  text-align: center;
}
.empty-cat { width: 120px; height: 120px; object-fit: contain; margin-bottom: 12px; }
.empty-bubble {
  background: var(--card);
  border-radius: 16px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-sub);
  box-shadow: var(--shadow);
  border: 1.5px solid var(--border);
}

/* ===== CATEGORY LIST PAGE ===== */
.segment-ctrl { display: flex; background: var(--mint-light); border-radius: 20px; padding: 3px; margin: 12px 0 0; }
.segment-btn { flex: 1; height: 32px; border-radius: 17px; font-size: 13px; font-weight: 700; color: var(--mint-dark); transition: all 0.2s; }
.segment-btn.active { background: var(--card); color: var(--text); box-shadow: var(--shadow); }

.term-list { display: flex; flex-direction: column; gap: 8px; padding: 16px; }

/* ===== INDEX BAR ===== */
.index-bar-wrap { position: relative; }
.index-bar {
  position: fixed;
  right: calc(50% - 215px);
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 1px;
  z-index: 40;
}
.index-char {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: var(--mint-dark);
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.1s;
}
.index-char:active, .index-char.highlight { background: var(--mint); }

/* Section header in list */
.list-section-header {
  font-size: 12px;
  font-weight: 800;
  color: var(--mint-dark);
  background: var(--mint-light);
  padding: 4px 12px;
  border-radius: 8px;
  margin-top: 8px;
  display: inline-block;
}

/* ===== TERM DETAIL PAGE ===== */
.detail-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(250,252,252,0.95);
  backdrop-filter: blur(12px);
  padding: 52px 16px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1.5px solid var(--border);
}
.detail-content { padding: 16px; display: flex; flex-direction: column; gap: 12px; }

.detail-name-card {
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow);
  border: 1.5px solid var(--border);
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.detail-name-text { flex: 1; }
.detail-name { font-size: 28px; font-weight: 800; color: var(--text); line-height: 1.2; margin-bottom: 4px; }
.detail-kana { font-size: 14px; color: var(--text-sub); margin-bottom: 4px; }
.detail-en { font-family: var(--font-en); font-size: 13px; color: var(--text-sub); font-weight: 600; margin-bottom: 8px; }
.detail-abbr {
  display: inline-block;
  background: var(--mint-light);
  color: var(--mint-dark);
  font-family: var(--font-en);
  font-size: 14px;
  font-weight: 800;
  padding: 4px 12px;
  border-radius: 20px;
}
.detail-cat-img { width: 70px; height: 70px; object-fit: contain; flex-shrink: 0; }

.detail-section {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  border: 1.5px solid var(--border);
}
.detail-section-title {
  font-size: 12px;
  font-weight: 800;
  color: var(--text-sub);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.detail-definition { font-size: 14px; line-height: 1.75; color: var(--text); }

.indications-box {
  background: #FFF0F5;
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  border: 1.5px solid var(--pink);
}
.indications-title {
  font-size: 12px;
  font-weight: 800;
  color: var(--pink-dark);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.indication-item { display: flex; align-items: baseline; gap: 8px; font-size: 14px; color: var(--text); margin-bottom: 6px; line-height: 1.5; }
.indication-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--pink-dark); flex-shrink: 0; }

.point-box {
  background: var(--mint-light);
  border-radius: var(--radius);
  padding: 14px 16px;
  border: 1.5px solid var(--mint);
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.point-cat { width: 56px; height: 56px; object-fit: contain; flex-shrink: 0; }
.point-content {}
.point-label {
  font-size: 12px;
  font-weight: 800;
  color: var(--mint-dark);
  margin-bottom: 6px;
}
.point-text { font-size: 13px; line-height: 1.7; color: var(--text); }

.related-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.related-chip {
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s;
  border: none;
}
.related-chip:active { transform: scale(0.95); }
.chip-0 { background: var(--mint-light); color: var(--mint-dark); }
.chip-1 { background: var(--pink); color: var(--pink-dark); }
.chip-2 { background: var(--lavender); color: #9970CC; }
.chip-3 { background: var(--orange); color: #CC9040; }

/* ===== SEARCH PAGE ===== */
.search-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(250,252,252,0.95);
  backdrop-filter: blur(12px);
  padding: 52px 16px 12px;
  border-bottom: 1.5px solid var(--border);
}
.search-result-count {
  font-size: 13px;
  color: var(--text-sub);
  font-weight: 600;
  padding: 10px 16px 0;
}
.search-result-count span { color: var(--mint-dark); font-weight: 800; }
.search-list { padding: 8px 16px 16px; display: flex; flex-direction: column; gap: 8px; }
.search-result-item {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  border: 1.5px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  transition: transform 0.15s;
}
.search-result-item:active { transform: scale(0.98); }
.search-result-body { flex: 1; min-width: 0; }
.search-result-name { font-size: 15px; font-weight: 700; color: var(--text); }
.search-result-en { font-family: var(--font-en); font-size: 12px; color: var(--text-sub); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-result-arrow { color: var(--text-sub); font-size: 16px; margin-left: 8px; flex-shrink: 0; }

/* Highlight matching text */
mark { background: var(--mint); color: var(--text); padding: 0 2px; border-radius: 2px; }

/* ===== FAVORITES & HISTORY PAGE ===== */
.list-page-header {
  padding: 52px 16px 16px;
  background: linear-gradient(160deg, var(--mint) 0%, var(--bg) 100%);
}
.list-page-title { font-size: 20px; font-weight: 800; display: flex; align-items: center; gap: 8px; }

/* ===== ABOUT PAGE ===== */
.about-content { padding: 20px 16px; }
.about-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  border: 1.5px solid var(--border);
  margin-bottom: 12px;
  text-align: center;
}
.about-app-icon { width: 80px; height: 80px; border-radius: 20px; margin: 0 auto 12px; display: block; }
.about-app-name { font-size: 18px; font-weight: 800; }
.about-app-sub { font-size: 13px; color: var(--text-sub); margin-top: 4px; }
.about-version { font-family: var(--font-en); font-size: 12px; color: var(--text-sub); margin-top: 8px; }
.about-pwa-card { background: var(--mint-light); border-radius: var(--radius); padding: 16px; border: 1.5px solid var(--mint); }
.about-pwa-title { font-size: 14px; font-weight: 800; color: var(--mint-dark); margin-bottom: 8px; }
.about-pwa-text { font-size: 13px; color: var(--text); line-height: 1.7; }

/* ===== LOADING ===== */
.loading-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  gap: 16px;
}
.loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--mint);
  border-top-color: var(--mint-dark);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== STAR ANIMATION ===== */
@keyframes starPop {
  0% { transform: scale(1); }
  50% { transform: scale(1.4); }
  100% { transform: scale(1); }
}
.star-pop { animation: starPop 0.3s ease; }

/* ===== SCROLLBAR HIDE ===== */
.scroll-hide { scrollbar-width: none; }
.scroll-hide::-webkit-scrollbar { display: none; }
