:root {
  --ink: #241817;
  --muted: #766865;
  --paper: #fbf7ef;
  --panel: #fffdf8;
  --line: #e8dccd;
  --red: #7a1f2b;
  --red-2: #a83a45;
  --gold: #d7a84e;
  --green: #2d6a55;
  --blue: #356d8f;
  --shadow: 0 14px 40px rgba(60, 32, 20, .14);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(122,31,43,.08), transparent 240px),
    var(--paper);
}

button, input, textarea { font: inherit; }

button {
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
}

.app-shell {
  width: min(100%, 480px);
  min-height: 100vh;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 14px calc(78px + env(safe-area-inset-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 0 10px;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(16px);
}

.eyebrow, .label {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1, h2, h3, p { margin-top: 0; }

h1 {
  margin: 2px 0 0;
  font-size: clamp(22px, 8vw, 32px);
  line-height: 1.05;
}

h2 { margin-bottom: 0; font-size: 22px; }
h3 { margin-bottom: 8px; font-size: 14px; }

.hidden { display: none !important; }

.hero-panel {
  display: grid;
  gap: 12px;
  margin-bottom: 14px;
}

.hero-panel > img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.session-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.timer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

#timerText {
  display: block;
  min-width: 116px;
  font-size: 38px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.primary-btn, .secondary-btn, .text-btn, .icon-button, .wide-action, .photo-btn {
  min-height: 44px;
  border-radius: 8px;
  font-weight: 800;
}

.primary-btn {
  padding: 0 16px;
  color: white;
  background: var(--red);
}

.secondary-btn {
  padding: 0 14px;
  color: var(--red);
  background: #f3e5d8;
}

.text-btn {
  min-height: 36px;
  padding: 0 8px;
  color: var(--red);
  background: transparent;
}

.wide-action {
  width: 100%;
  margin: -4px 0 12px;
  border: 1px dashed var(--red);
  color: var(--red);
  background: #fff8ed;
}

.icon-button {
  width: 44px;
  color: var(--ink);
  background: #f2e8dc;
  font-size: 24px;
}

.meter {
  height: 8px;
  margin: 14px 0 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #eadfd4;
}

.meter span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), var(--gold), var(--red-2));
  transition: width .25s ease;
}

.session-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.session-stats span {
  min-height: 34px;
  padding: 8px;
  border-radius: 8px;
  background: #f7efe5;
}

.session-stats b {
  color: var(--ink);
  font-size: 18px;
}

.view { display: none; }
.view.active { display: block; }

.command-strip {
  position: sticky;
  top: 76px;
  z-index: 4;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin: 0 -2px 12px;
  padding: 8px 2px;
  background: color-mix(in srgb, var(--paper) 86%, transparent);
  backdrop-filter: blur(16px);
}

.focus-pick {
  padding: 14px;
  margin-bottom: 14px;
  border-radius: 8px;
  background: #213b34;
  color: #fffaf0;
}

.focus-pick h2 {
  margin: 4px 0 8px;
  font-size: 20px;
}

.focus-pick p {
  margin-bottom: 10px;
  color: #f4e9ce;
  line-height: 1.45;
}

.field-stack { display: grid; gap: 10px; margin-bottom: 12px; }

.search-box, .note-box {
  display: grid;
  gap: 6px;
  font-weight: 800;
  color: var(--muted);
  font-size: 12px;
}

.compact-search { margin-bottom: 12px; }

input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
}

input { height: 46px; padding: 0 12px; }
textarea { resize: vertical; padding: 12px; line-height: 1.5; }

.chip-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.chip-row::-webkit-scrollbar { display: none; }

.chip {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: var(--panel);
  font-size: 13px;
  font-weight: 800;
}

.chip.active, .selectable .chip.active {
  border-color: var(--red);
  color: white;
  background: var(--red);
}

.sake-list, .prep-list, .ranking-list, .timeline {
  display: grid;
  gap: 10px;
}

.sake-card, .prep-card, .rank-card, .log-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 6px 18px rgba(63, 39, 24, .06);
}

.sake-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 12px;
}

.sake-title {
  margin: 0 0 6px;
  font-size: 16px;
  line-height: 1.3;
}

.meta-line {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: #f4eadf;
  color: #5f524e;
  font-weight: 750;
}

.flavor-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  padding: 3px 7px;
  border-radius: 6px;
  background: #eef4ef;
  color: #285f4b;
  font-size: 12px;
  font-weight: 700;
}

.score-badge {
  align-self: start;
  min-width: 48px;
  padding: 8px 6px;
  border-radius: 8px;
  background: #f7efe5;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.score-badge b {
  display: block;
  font-size: 18px;
}

.card-actions {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 6px 0 12px;
}

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

.framework-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.framework-item {
  min-height: 92px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.framework-item h3 {
  margin: 0 0 4px;
  color: var(--red);
}

.framework-item p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.prep-card, .rank-card, .log-card { padding: 12px; }

.prep-card p, .rank-card p, .log-card p {
  margin-bottom: 8px;
  color: #51433f;
  line-height: 1.5;
}

.log-photo, .rank-photo {
  width: 100%;
  max-height: 220px;
  object-fit: cover;
  border-radius: 8px;
  margin: 4px 0 8px;
  border: 1px solid var(--line);
}

.rank-card {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  align-items: start;
  gap: 10px;
}

.rank-media {
  grid-column: 2 / -1;
}

.rank-num {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--red);
  color: white;
  font-weight: 900;
}

.stats-panel {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.stat-tile {
  min-height: 72px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.stat-tile b {
  display: block;
  font-size: 24px;
  line-height: 1.1;
}

.stat-tile span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.chart-card {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.chart-card h3 { margin-top: 0; }

.bar-row {
  display: grid;
  grid-template-columns: 72px 1fr 32px;
  align-items: center;
  gap: 8px;
  margin: 8px 0;
  font-size: 12px;
  color: var(--muted);
  font-weight: 800;
}

.bar-track {
  height: 14px;
  overflow: hidden;
  border-radius: 999px;
  background: #f0e5d9;
}

.bar-fill {
  height: 100%;
  min-width: 3px;
  border-radius: inherit;
  background: var(--green);
}

.term-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.term-cloud .tag {
  background: #f8eddb;
  color: #67481c;
}

.bottom-nav {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 8;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  width: min(100%, 480px);
  margin: 0 auto;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(251, 247, 239, .92);
  backdrop-filter: blur(18px);
}

.nav-btn {
  min-height: 50px;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  font-size: 16px;
  font-weight: 900;
}

.nav-btn.active {
  color: white;
  background: var(--red);
}

dialog {
  width: min(calc(100vw - 22px), 460px);
  max-height: calc(100vh - 26px);
  border: 0;
  border-radius: 8px;
  padding: 0;
  color: var(--ink);
  background: var(--panel);
  box-shadow: var(--shadow);
}

dialog::backdrop { background: rgba(28, 18, 16, .48); }

.taste-form, .menu-dialog {
  display: grid;
  gap: 14px;
  padding: 14px;
}

.dialog-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.dialog-head h2 {
  font-size: 20px;
  line-height: 1.25;
}

.rating-picker {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.rating-btn {
  min-height: 48px;
  border-radius: 8px;
  color: var(--red);
  background: #f3e5d8;
  font-size: 20px;
  font-weight: 900;
}

.rating-btn.active {
  color: white;
  background: var(--red);
}

.photo-block {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff8ed;
}

.photo-block h3 { margin: 0 0 4px; }

.photo-block p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.photo-btn {
  position: relative;
  display: grid;
  place-items: center;
  width: 74px;
  color: white;
  background: var(--blue);
}

.photo-btn input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.photo-preview {
  display: grid;
  grid-template-columns: 86px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.photo-preview img {
  width: 86px;
  height: 86px;
  object-fit: cover;
  border-radius: 8px;
}

.slider-grid { display: grid; gap: 10px; }

.slider-row {
  display: grid;
  grid-template-columns: 68px 1fr 28px;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

input[type="range"] { height: 32px; padding: 0; accent-color: var(--red); }

.term-block { display: grid; gap: 2px; }

.dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0;
  padding: 0;
}

.menu-dialog img {
  width: 100%;
  border-radius: 8px;
}

@media (max-width: 374px) {
  .app-shell { padding-right: 10px; padding-left: 10px; }
  h1 { font-size: 24px; }
  #timerText { min-width: 104px; font-size: 34px; }
  .framework-grid { grid-template-columns: 1fr; }
  .sake-card { grid-template-columns: 1fr; }
  .score-badge { justify-self: start; }
}
