:root {
  --ink: #17233c;
  --muted: #6f7d96;
  --line: #e4e9f2;
  --panel: rgba(255, 255, 255, .92);
  --acid: #ff5577;
  --acid-dark: #df355a;
  --acid-soft: #fff0f4;
  --base: #3379f6;
  --base-dark: #1d5dd5;
  --base-soft: #edf4ff;
  --water: #45c7c0;
  --navy: #1c2c4e;
  --shadow: 0 18px 55px rgba(38, 56, 95, .10);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: #f5f8fd; }
body { margin: 0; color: var(--ink); font-family: "Yu Gothic UI", "Hiragino Sans", system-ui, sans-serif; background: linear-gradient(155deg, #fbfdff 0%, #f4f8ff 48%, #fff9fb 100%); min-height: 100vh; }
button, input, select { font: inherit; }
button { color: inherit; }
.ambient { position: fixed; border-radius: 50%; filter: blur(2px); pointer-events: none; opacity: .55; }
.ambient-a { width: 420px; height: 420px; right: -180px; top: 130px; background: radial-gradient(circle, #dce9ff, transparent 68%); }
.ambient-b { width: 380px; height: 380px; left: -180px; bottom: -80px; background: radial-gradient(circle, #ffe1e9, transparent 70%); }

.app-header { min-height: 52px; padding: 6px; display: flex; align-items: stretch; background: rgba(255,255,255,.92); border: 1px solid rgba(222,228,239,.9); border-radius: 16px; box-shadow: var(--shadow); overflow: hidden; }
.mode-tabs { width: 100%; background: #eef2f8; border-radius: 11px; padding: 4px; display: flex; gap: 3px; }
.tab { flex: 1; border: 0; background: transparent; color: #78849a; font-weight: 700; padding: 8px 5px; border-radius: 9px; cursor: pointer; transition: .2s; font-size: 11px; }
.tab.active { background: white; color: var(--ink); box-shadow: 0 3px 10px rgba(37,55,90,.10); }

main { position: relative; z-index: 1; padding: 35px clamp(20px, 3.7vw, 58px) 44px; max-width: 1680px; margin: auto; }
.mode-view { display: none; }
.mode-view.active { display: block; animation: reveal .3s ease-out; }
@keyframes reveal { from { opacity: 0; transform: translateY(5px); } }
.intro-row { display: flex; justify-content: space-between; align-items: flex-end; margin: 0 auto 23px; }
.eyebrow { margin: 0 0 4px; color: var(--base); font-size: 10px; font-weight: 800; letter-spacing: .22em; }
.intro-row h1 { font-size: clamp(24px, 2.2vw, 34px); letter-spacing: -.03em; margin: 0; }
.intro-row > p { color: var(--muted); font-size: 12px; line-height: 1.8; margin: 0; text-align: right; }

.workspace-grid { display: grid; grid-template-columns: minmax(260px, .72fr) minmax(520px, 1.8fr); grid-template-rows: 52px minmax(0, 1fr); gap: 16px; align-items: stretch; min-height: 650px; }
.workspace-grid > .app-header { grid-column: 1; grid-row: 1; }
.workspace-grid > .controls-panel { grid-column: 1; grid-row: 2; min-height: 0; overflow-y: auto; }
.workspace-grid > .lab-panel { grid-column: 2; grid-row: 1 / 3; min-height: 0; }
.panel { background: var(--panel); border: 1px solid rgba(222,228,239,.9); border-radius: 22px; box-shadow: var(--shadow); overflow: hidden; }
.controls-panel, .graph-panel { padding: 24px; }
.panel-title { display: flex; gap: 12px; align-items: center; margin-bottom: 22px; }
.panel-title .step { display: grid; place-items: center; flex: 0 0 30px; height: 30px; border-radius: 10px; background: var(--navy); color: white; font-weight: 800; font-size: 12px; }
.panel-title h2 { margin: 0; font-size: 16px; }
.panel-title p { margin: 3px 0 0; color: var(--muted); font-size: 10px; }
.segmented { background: #f0f3f8; border-radius: 11px; padding: 4px; display: grid; grid-template-columns: 1fr 1fr; margin-bottom: 18px; }
.segmented button { border: 0; border-radius: 8px; padding: 8px 4px; font-weight: 700; color: var(--muted); font-size: 12px; background: transparent; cursor: pointer; }
.segmented button.active { color: var(--ink); background: white; box-shadow: 0 2px 8px rgba(39,57,91,.08); }
.control-label { display: block; color: var(--muted); font-size: 9px; font-weight: 700; margin: -3px 0 6px; }
.ion-view-tabs { margin-bottom: 18px; }
.reagent-controls { display: none; }
.reagent-controls.active { display: block; }
.reagent-selectors { display: grid; grid-template-columns: 1fr auto 1fr; gap: 7px; align-items: start; margin-bottom: 7px; }
.reagent-selectors > span { color: var(--muted); padding-top: 31px; font-weight: 700; }
.reagent-selectors label, .reagent-column > span { color: var(--muted); font-size: 9px; font-weight: 700; }
.reagent-selectors select { display: block; width: 100%; margin-top: 4px; padding: 9px 7px; border: 1px solid var(--line); border-radius: 9px; background: white; color: var(--ink); font-weight: 800; }
.acid-choice-list, .base-choice-list { display: grid; gap: 4px; margin-top: 4px; }
.acid-choice, .base-choice { width: 100%; padding: 7px 8px; border: 1px solid var(--line); border-radius: 8px; background: white; color: var(--ink); font-weight: 800; font-size: 10px; text-align: left; cursor: pointer; }
.acid-choice.active { border-color: #ff9bb0; background: var(--acid-soft); color: var(--acid-dark); box-shadow: inset 3px 0 0 var(--acid); }
.base-choice.active { border-color: #9bbcff; background: var(--base-soft); color: var(--base-dark); box-shadow: inset 3px 0 0 var(--base); }
.native-reagent-select { position: absolute !important; width: 1px !important; height: 1px !important; margin: -1px !important; padding: 0 !important; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0 !important; }
.model-assumption { color: var(--muted); font-size: 8px; line-height: 1.55; margin: 0 0 15px; padding-left: 9px; border-left: 2px solid #d9e2f0; }
.input-group { display: none; }
.input-group.active { display: block; }
.range-card { --slider-color: var(--acid); display: grid; grid-template-columns: 1fr auto; border: 1px solid var(--line); border-radius: 15px; padding: 14px 14px 12px; margin-bottom: 11px; }
.range-card > span { display: flex; align-items: baseline; gap: 8px; }
.range-card b { font-family: inherit; font-size: 20px; }
.range-card small { color: var(--muted); font-size: 10px; }
.range-card output { font-weight: 800; font-size: 15px; }
.range-card.base-card { --slider-color: var(--base); }
.range-card input[type="range"] { appearance: none; grid-column: 1/-1; width: 100%; height: 8px; margin-top: 13px; border: 1px solid #d6deea; border-radius: 999px; background: linear-gradient(to right, var(--slider-color) 0 var(--range-progress, 0%), #fff var(--range-progress, 0%) 100%); }
.range-card input[type="range"]::-webkit-slider-thumb { appearance: none; width: 16px; height: 16px; border: 2px solid #fff; border-radius: 50%; background: var(--slider-color); box-shadow: 0 1px 4px rgba(35, 51, 83, .24); cursor: pointer; }
.range-card input[type="range"]::-moz-range-track { height: 6px; border: 1px solid #d6deea; border-radius: 999px; background: #fff; }
.range-card input[type="range"]::-moz-range-progress { height: 6px; border-radius: 999px; background: var(--slider-color); }
.range-card input[type="range"]::-moz-range-thumb { width: 12px; height: 12px; border: 2px solid #fff; border-radius: 50%; background: var(--slider-color); box-shadow: 0 1px 4px rgba(35, 51, 83, .24); cursor: pointer; }
.acid-card { background: var(--acid-soft); border-color: #ffdbe4; }
.acid-card b, .acid-card output { color: var(--acid-dark); }
.base-card { background: var(--base-soft); border-color: #dae7ff; }
.base-card b, .base-card output { color: var(--base-dark); }
.presets { margin: 17px 0; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.presets span { color: var(--muted); font-size: 10px; margin-right: 4px; }
.presets button { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 9px; font-size: 9px; cursor: pointer; }
.presets button:hover { border-color: #8092b3; background: #f3f6fb; }
.solution-block { border-radius: 14px; padding: 13px; margin-bottom: 10px; }
.solution-block h3 { font-size: 11px; margin: 0 0 10px; }
.acid-tint { background: var(--acid-soft); }
.base-tint { background: var(--base-soft); }
.two-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.solution-field { min-width: 0; color: var(--muted); font-size: 9px; }
.solution-field > label { display: flex; align-items: baseline; justify-content: space-between; gap: 3px; font-weight: 700; }
.solution-field > label small { font-size: 8px; font-weight: 500; }
.number-stepper { display: grid; grid-template-columns: 28px minmax(0, 1fr) 28px; margin-top: 4px; }
.number-stepper button, .number-stepper input { min-width: 0; height: 34px; border: 1px solid #d5deeb; background: rgba(255,255,255,.94); color: var(--ink); }
.number-stepper button { display: grid; place-items: center; padding: 0; font-size: 16px; font-weight: 800; line-height: 1; cursor: pointer; touch-action: manipulation; }
.number-stepper button:first-child { border-radius: 8px 0 0 8px; }
.number-stepper button:last-child { border-radius: 0 8px 8px 0; }
.number-stepper button:active { background: #e9eef6; }
.number-stepper button:disabled { color: #aeb8c8; cursor: default; }
.number-stepper input { width: 100%; padding: 4px 1px; border-right: 0; border-left: 0; border-radius: 0; color: var(--ink); font-size: 16px; font-weight: 700; text-align: center; appearance: textfield; }
.number-stepper input::-webkit-inner-spin-button, .number-stepper input::-webkit-outer-spin-button { margin: 0; appearance: none; }

.lab-panel { position: relative; display: flex; flex-direction: column; background: linear-gradient(180deg, rgba(255,255,255,.95), rgba(247,251,255,.94)); }
.lab-head { height: 62px; border-bottom: 1px solid var(--line); padding: 0 20px; display: flex; align-items: center; justify-content: space-between; }
.lab-head > div:first-child { display: grid; grid-template-columns: auto auto; align-items: center; column-gap: 7px; }
.lab-head small { grid-column: 2; color: var(--muted); font-size: 9px; }
.live-dot { width: 7px; height: 7px; background: #3dd19a; border-radius: 50%; box-shadow: 0 0 0 4px #e3f9f1; }
.legend { display: flex; gap: 13px; font-size: 9px; color: var(--muted); }
.legend span::before { content:""; display:inline-block; width:8px; height:8px; border-radius:50%; margin-right:4px; vertical-align:-1px; }
.legend .acid-dot::before { background: var(--acid); }
.legend .base-dot::before { background: var(--base); }
.legend .chloride-dot::before { background: #32a852; }
.legend .sodium-dot::before { background: #f59e0b; }
.legend .water-dot::before { background: var(--water); }
.legend .legend-item::before { background: var(--legend-color); }
.particle-stage { flex: 1 1 auto; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 160px; }
#particle-canvas { width: 100%; height: 100%; min-height: 500px; display: block; }
.particle-counts { border-left: 1px solid var(--line); padding: 16px 15px; background: rgba(248,251,255,.86); display: flex; flex-direction: column; justify-content: flex-start; }
.particle-counts > b { margin-bottom: 11px; color: var(--muted); font-size: 9px; letter-spacing: .08em; }
#particle-count-list { display: grid; gap: 9px; }
.particle-count-item { min-height: 36px; display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.count-particle { position: relative; flex: 0 0 34px; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; color: white; background: radial-gradient(circle at 34% 28%, #fff 0 5%, var(--particle-color) 24%, var(--particle-dark) 100%); box-shadow: 0 4px 9px color-mix(in srgb, var(--particle-color) 35%, transparent); font-size: 8px; font-weight: 800; line-height: 1; z-index: 0; }
.count-particle.long { font-size: 6.5px; }
.count-particle.water { width: 30px; height: 30px; margin: 2px; background: var(--water); overflow: visible; }
.count-particle.water::before, .count-particle.water::after { content: ""; position: absolute; z-index: 0; bottom: -4px; width: 15px; height: 15px; border-radius: 50%; background: #a8eeea; }
.count-particle.water::before { left: -5px; }
.count-particle.water::after { right: -5px; }
.particle-count-item strong { min-width: 3em; color: var(--ink); font-size: 13px; text-align: right; }
.solution-state { display: none; margin-top: 16px; padding: 12px 8px 0; border-top: 1px solid var(--line); text-align: center; }
.solution-state.show { display: block; }
.solution-state small { display: block; margin-bottom: 6px; color: var(--muted); font-size: 8px; }
.solution-state strong { display: inline-block; min-width: 64px; padding: 6px 10px; border-radius: 999px; background: #e8f9f7; color: #188f89; font-size: 12px; }
.solution-state.acidic strong { background: var(--acid-soft); color: var(--acid-dark); }
.solution-state.basic strong { background: var(--base-soft); color: var(--base-dark); }
.playback { height: 64px; border-top: 1px solid var(--line); display: flex; align-items: center; justify-content: center; gap: 10px; padding: 0 18px; }
.icon-button, .play-button, .primary-button, .secondary-button { border: 0; cursor: pointer; font-weight: 800; transition: transform .15s, box-shadow .15s; }
.icon-button:active, .play-button:active, .primary-button:active, .secondary-button:active { transform: translateY(1px); }
.icon-button { width: 38px; height: 38px; display: inline-grid; place-items: center; padding: 0; border-radius: 12px; background: #eef2f8; line-height: 1; }
.icon-button svg { display: block; width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.1; stroke-linecap: round; stroke-linejoin: round; }
.play-button, .primary-button { border-radius: 12px; padding: 11px 25px; background: var(--navy); color: white; box-shadow: 0 8px 18px rgba(28,44,78,.18); }
.play-button span { color: #83aaff; }
.playback label { font-size: 9px; color: var(--muted); margin-left: auto; }
.playback select { margin-left: 5px; border: 1px solid var(--line); border-radius: 8px; padding: 6px; font-size: 9px; background: white; }

.titration-grid { display: grid; grid-template-columns: minmax(280px,.72fr) minmax(520px,1.8fr); grid-template-rows: 52px minmax(0, 1fr); gap: 16px; min-height: 650px; }
.titration-grid > .app-header { grid-column: 1; grid-row: 1; }
.titration-grid > .titration-settings { grid-column: 1; grid-row: 2; min-height: 0; overflow-y: auto; }
.titration-grid > .titration-lab { grid-column: 2; grid-row: 1 / 3; }
.secondary-button { background: #edf1f7; border-radius: 12px; padding: 11px 17px; }
.titration-lab { display: flex; flex-direction: column; }
.titration-particle-stage { flex: 1 1 auto; min-height: 0; display: grid; grid-template-columns: minmax(0,1fr) 160px; }
.titration-stage { min-height: 470px; position: relative; background: linear-gradient(#fafdff, #f2f7fd); }
#titration-canvas { width: 100%; height: 100%; display: block; }
.volume-badge { position: absolute; top: 18px; right: 18px; background: rgba(255,255,255,.9); border: 1px solid var(--line); border-radius: 13px; padding: 9px 12px; text-align: right; box-shadow: 0 7px 20px rgba(38,56,95,.08); }
.volume-badge small { display: block; color: var(--muted); font-size: 8px; }
.volume-badge strong { font-size: 19px; margin-right: 3px; }
.volume-badge span { font-size: 9px; color: var(--muted); }
.titration-controls { display: grid; grid-template-columns: auto auto 1fr; align-items: center; height: 64px; box-sizing: border-box; gap: 9px; border-top: 1px solid var(--line); padding: 0 13px; }
.titration-controls .icon-button { grid-column: 1; justify-self: start; }
.titration-controls .primary-button { grid-column: 2; justify-self: start; }
.titration-controls label { grid-column: 3; justify-self: end; color: var(--muted); font-size: 9px; font-weight: 700; }
.titration-controls select { margin-left: 5px; border: 1px solid var(--line); border-radius: 8px; padding: 6px 7px; background: white; color: var(--ink); font: inherit; }
#titration-count-list { display: grid; gap: 9px; }
.titration-counts .solution-state { margin-top: 14px; }
.titration-summary { display: grid; gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.titration-summary div { display: flex; align-items: baseline; justify-content: space-between; gap: 6px; }
.titration-summary small { color: var(--muted); font-size: 8px; }
.titration-summary strong { text-align: right; font-size: 10px; }
#toast { position: fixed; left: 50%; bottom: 25px; transform: translate(-50%, 15px); background: var(--navy); color: white; padding: 10px 18px; border-radius: 10px; font-size: 11px; opacity: 0; pointer-events: none; transition: .25s; z-index: 50; box-shadow: 0 10px 30px rgba(28,44,78,.25); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 1100px) {
  .workspace-grid, .titration-grid { grid-template-columns: 280px 1fr; }
}
@media (min-width: 721px) and (max-width: 1180px) and (orientation: landscape) {
  main { padding: 14px 20px 16px; }
  #stoich-mode.active, #titration-mode.active { display: flex; flex-direction: column; height: calc(100svh - 30px); min-height: 0; }
  .workspace-grid, .titration-grid { flex: 1 1 auto; grid-template-columns: 285px minmax(0, 1fr); grid-template-rows: 52px minmax(0, 1fr); gap: 12px; min-height: 0; }
  .workspace-grid > .controls-panel { grid-column: 1; grid-row: 2; min-height: 0; }
  .workspace-grid > .lab-panel { grid-column: 2; grid-row: 1 / 3; min-height: 0; }
  .controls-panel { padding: 12px 16px; }
  .panel-title { margin-bottom: 12px; }
  .segmented, .ion-view-tabs { margin-bottom: 10px; }
  .model-assumption { margin-bottom: 8px; }
  .range-card { padding: 10px 12px 9px; margin-bottom: 8px; }
  .range-card input { margin-top: 8px; }
  .presets { margin: 10px 0 0; }
  .lab-head { height: 52px; }
  #particle-canvas { min-height: 0; }
  .titration-stage { min-height: 0; }
  .particle-counts { padding: 12px 10px; }
  .playback { height: 64px; }
}
@media (min-width: 721px) and (max-width: 1180px) and (orientation: landscape) and (max-height: 700px) {
  .panel-title { margin-bottom: 8px; }
  .panel-title p, .controls-panel .model-assumption { display: none; }
  .segmented button { padding-top: 6px; padding-bottom: 6px; }
  .acid-choice, .base-choice { padding: 5px 7px; }
  .solution-block { padding: 9px 10px; margin-bottom: 7px; }
  .solution-block h3 { margin-bottom: 6px; }
}
@media (max-width: 720px) {
  main { padding: 24px 12px; }
  .intro-row { align-items: flex-start; }
  .intro-row > p { display: none; }
  .workspace-grid, .titration-grid { grid-template-columns: 1fr; grid-template-rows: auto; min-height: 0; }
  .workspace-grid > .app-header, .workspace-grid > .controls-panel, .workspace-grid > .lab-panel,
  .titration-grid > .app-header, .titration-grid > .titration-settings, .titration-grid > .titration-lab { grid-column: 1; grid-row: auto; }
  .workspace-grid > .controls-panel, .titration-grid > .titration-settings { overflow-y: visible; }
  .particle-stage, .titration-particle-stage { position: relative; display: block; }
  #particle-canvas { min-height: 420px; }
  .particle-counts { position: absolute; top: 10px; right: 10px; width: 142px; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; background: rgba(255,255,255,.92); }
  .particle-counts > b { margin-bottom: 8px; }
  #particle-count-list { gap: 5px; }
  .count-particle { width: 30px; height: 30px; flex-basis: 30px; }
  .lab-panel { min-height: 560px; }
  .titration-counts { position: absolute; top: 10px; right: 10px; width: 142px; border: 1px solid var(--line); border-radius: 12px; background: rgba(255,255,255,.92); }
  .titration-stage { min-height: 430px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
