:root {
  --bg: #efe7d8;
  --surface: #faf6ec;
  --surface-2: #f2ead9;
  --ink: #1d2a24;
  --ink-soft: #3d4b43;
  --muted: #7a857c;
  --line: #d8cdb8;
  --accent: #b3541e;
  --accent-2: #2e6457;
  --gold: #a9852c;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-quart: cubic-bezier(0.16, 1, 0.3, 1);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: var(--tg-viewport-stable-height, 100dvh);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  background: var(--bg);
  color: var(--ink);
  font-family: "Manrope", system-ui, -apple-system, sans-serif;
}

body {
  background:
    radial-gradient(120% 70% at 0% 0%, #f8f1e3 0%, rgba(248, 241, 227, 0) 58%),
    radial-gradient(90% 55% at 100% 0%, #f3e4cd 0%, rgba(243, 228, 205, 0) 55%),
    var(--bg);
}

input,
textarea,
[contenteditable="true"] {
  user-select: text;
  font-size: 16px;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}

#app {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.app-header {
  flex-shrink: 0;
  padding: calc(10px + var(--safe-top)) 18px 0;
  z-index: 10;
}

.app-header::after {
  content: "";
  display: block;
  height: 1px;
  margin-top: 12px;
  background: var(--line);
  opacity: 0.75;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
}

.brand__mark {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: var(--ink);
  color: #f6eedf;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.brand__title {
  font-family: "Fraunces", Georgia, serif;
  font-size: 21px;
  font-weight: 600;
  line-height: 1.05;
  letter-spacing: -0.01em;
}

.brand__sub {
  margin-top: 3px;
  font-size: 10.5px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
}

.app-viewport {
  flex: 1;
  position: relative;
  min-height: 0;
  overflow: hidden;
}

.view {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  scrollbar-gutter: stable;
}

.view[hidden] {
  display: none;
}

.view__pad {
  padding: 14px 16px 28px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  box-shadow: 0 1px 0 rgba(29, 42, 36, 0.04);
}

.card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.card__head h2 {
  margin: 0;
  font-family: "Fraunces", Georgia, serif;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.hint {
  font-size: 10.5px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 12px;
  line-height: 1.45;
}

.hero {
  position: relative;
  overflow: hidden;
  border-radius: 22px;
  padding: 18px 18px 16px;
  color: #f6eedf;
  background: linear-gradient(145deg, #22312a 0%, #1a2721 100%);
}

.hero::after {
  content: "";
  position: absolute;
  right: -34px;
  top: -46px;
  width: 150px;
  height: 150px;
  border-radius: 50%;
  border: 1px solid rgba(246, 238, 223, 0.16);
  pointer-events: none;
}

.hero__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.eyebrow {
  font-size: 10px;
  letter-spacing: 0.17em;
  text-transform: uppercase;
  color: rgba(246, 238, 223, 0.62);
}

.hero__period {
  font-size: 11px;
  color: rgba(246, 238, 223, 0.62);
}

.hero__num {
  font-family: "JetBrains Mono", monospace;
  font-size: 46px;
  font-weight: 500;
  line-height: 1.05;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.hero__split {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid rgba(246, 238, 223, 0.16);
}

.hero__split b {
  display: block;
  font-family: "JetBrains Mono", monospace;
  font-size: 16px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.hero__split span {
  display: block;
  margin-top: 2px;
  font-size: 10px;
  letter-spacing: 0.04em;
  color: rgba(246, 238, 223, 0.6);
}

.chart {
  display: grid;
  grid-template-columns: repeat(14, 1fr);
  gap: 5px;
  height: 132px;
  align-items: stretch;
}

.bar {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.bar__track {
  flex: 1;
  display: flex;
  align-items: flex-end;
  border-radius: 5px;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(29, 42, 36, 0.045), rgba(29, 42, 36, 0.02));
}

.bar__fill {
  width: 100%;
  height: 100%;
  border-radius: 5px 5px 3px 3px;
  background: linear-gradient(180deg, var(--accent) 0%, var(--gold) 100%);
  transform: scaleY(0);
  transform-origin: bottom center;
  transition: transform 560ms var(--ease-quart);
  will-change: transform;
}

.bar__fill.is-in {
  transform: scaleY(var(--h, 0));
}

.bar i {
  font-style: normal;
  font-size: 8.5px;
  text-align: center;
  color: var(--muted);
}

.grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.metric {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 13px 14px;
}

.metric span {
  display: block;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.metric b {
  display: block;
  margin-top: 6px;
  font-family: "JetBrains Mono", monospace;
  font-size: 23px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.seg {
  position: relative;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface-2);
  --n: 3;
  --seg-i: 0;
}

.seg__thumb {
  position: absolute;
  top: 3px;
  bottom: 3px;
  left: 3px;
  width: calc((100% - 6px) / var(--n));
  border-radius: 10px;
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(29, 42, 36, 0.1);
  transform: translate3d(calc(var(--seg-i) * 100%), 0, 0);
  transition: transform 240ms var(--ease-out);
  pointer-events: none;
}

.seg__btn {
  position: relative;
  z-index: 1;
  height: 34px;
  border-radius: 10px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  transition: color 180ms var(--ease-out);
}

.seg__btn.is-active {
  color: var(--ink);
}

.field {
  display: block;
  margin-bottom: 11px;
}

.field > span {
  display: block;
  margin-bottom: 6px;
  font-size: 10px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
}

.field input,
.field textarea,
.quick input {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--ink);
  font-family: inherit;
  line-height: 1.4;
  resize: none;
  outline: none;
  transition: border-color 160ms var(--ease-out), background 160ms var(--ease-out);
}

.field input:focus,
.field textarea:focus,
.quick input:focus {
  border-color: var(--accent-2);
  background: var(--surface);
}

.switch {
  position: relative;
  width: 48px;
  height: 28px;
  flex-shrink: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  transition: background 200ms var(--ease-out), border-color 200ms var(--ease-out);
}

.switch span {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  transition: transform 220ms var(--ease-out);
}

.switch[aria-checked="true"] {
  border-color: var(--accent-2);
  background: var(--accent-2);
}

.switch[aria-checked="true"] span {
  border-color: #ffffff;
  background: #ffffff;
  transform: translate3d(20px, 0, 0);
}

.action-btn {
  position: relative;
  width: 100%;
  height: 50px;
  overflow: hidden;
  border-radius: 15px;
  background: var(--accent);
  color: #fbf5e8;
  font-size: 15px;
  font-weight: 700;
  transition: background-color 200ms var(--ease-out), transform 140ms var(--ease-out);
}

.action-btn[data-state="done"] {
  background: var(--accent-2);
}

.action-btn__state {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  opacity: 0;
  transform: translate3d(0, 8px, 0);
  transition: opacity 180ms var(--ease-out), transform 180ms var(--ease-out);
  pointer-events: none;
}

.action-btn[data-state="idle"] .is-idle,
.action-btn[data-state="loading"] .is-loading,
.action-btn[data-state="done"] .is-done {
  opacity: 1;
  transform: translate3d(0, 0, 0);
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 650ms linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.check-svg path {
  stroke-dasharray: 24;
  stroke-dashoffset: 24;
  transition: stroke-dashoffset 260ms var(--ease-out) 60ms;
}

.action-btn[data-state="done"] .check-svg path {
  stroke-dashoffset: 0;
}

.award {
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 16px;
  padding: 14px 15px;
  background: var(--surface);
}

.award p {
  margin: 0;
  font-family: "Fraunces", Georgia, serif;
  font-size: 16.5px;
  line-height: 1.35;
}

.award__meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
  font-size: 11px;
  color: var(--muted);
}

.link-danger {
  padding: 4px 2px;
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
}

.empty {
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: 16px;
  background: rgba(250, 246, 236, 0.55);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  text-align: center;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.rowcard {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-2);
}

.rowcard__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.rowcard b {
  font-size: 13.5px;
}

.chip {
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.chip--on {
  border-color: var(--accent-2);
  background: var(--accent-2);
  color: #f6eedf;
}

.quick {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.btn {
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  font-size: 13.5px;
  font-weight: 700;
}

.btn--primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fbf5e8;
}

.connrow {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(216, 205, 184, 0.6);
}

.connrow:last-child {
  border-bottom: 0;
}

.connrow b {
  font-size: 13px;
}

.dot {
  width: 7px;
  height: 7px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--muted);
}

.dot--on {
  background: var(--accent-2);
}

.tabbar {
  flex-shrink: 0;
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--tabs, 4), 1fr);
  padding: 6px 8px calc(8px + var(--safe-bottom));
  border-top: 1px solid var(--line);
  background: var(--surface);
  z-index: 20;
}

.tabbar__pill {
  position: absolute;
  top: 6px;
  left: 8px;
  width: calc((100% - 16px) / var(--tabs, 4));
  height: 48px;
  border-radius: 14px;
  background: var(--surface-2);
  transform: translate3d(calc(var(--active, 0) * 100%), 0, 0);
  transition: transform 240ms var(--ease-out);
  pointer-events: none;
}

.tab {
  position: relative;
  z-index: 1;
  height: 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--muted);
  transition: color 180ms var(--ease-out);
}

.tab svg {
  width: 19px;
  height: 19px;
  transition: transform 200ms var(--ease-out);
}

.tab.is-active {
  color: var(--ink);
}

.tab.is-active svg {
  transform: translate3d(0, -1px, 0);
}

.toast {
  position: fixed;
  top: calc(10px + var(--safe-top));
  left: 50%;
  z-index: 80;
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--ink);
  color: #f6eedf;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(29, 42, 36, 0.18);
  opacity: 0;
  transform: translate3d(-50%, -14px, 0) scale(0.96);
  pointer-events: none;
  transition: opacity 200ms var(--ease-out), transform 220ms var(--ease-out);
}

.toast.is-shown {
  opacity: 1;
  transform: translate3d(-50%, 0, 0) scale(1);
}

.skel {
  position: relative;
  overflow: hidden;
  border-radius: 14px;
  background: rgba(29, 42, 36, 0.08);
}

.skel::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.32), transparent);
  transform: translate3d(-100%, 0, 0);
  animation: shimmer 1.25s infinite;
}

@keyframes shimmer {
  to { transform: translate3d(100%, 0, 0); }
}

@keyframes paneFromRight {
  from { opacity: 0; transform: translate3d(16px, 0, 0); }
  to { opacity: 1; transform: translate3d(0, 0, 0); }
}

@keyframes paneFromLeft {
  from { opacity: 0; transform: translate3d(-16px, 0, 0); }
  to { opacity: 1; transform: translate3d(0, 0, 0); }
}

.view.enter-right > .view__pad {
  animation: paneFromRight 220ms var(--ease-out) both;
}

.view.enter-left > .view__pad {
  animation: paneFromLeft 220ms var(--ease-out) both;
}

@keyframes cardRise {
  from { opacity: 0; transform: translate3d(0, 10px, 0); }
  to { opacity: 1; transform: translate3d(0, 0, 0); }
}

.stagger-list > * {
  animation: cardRise 240ms var(--ease-out) both;
  animation-delay: calc(min(var(--i, 0), 8) * 32ms);
}

.pressable {
  transition: transform 180ms var(--ease-out), opacity 180ms var(--ease-out);
  will-change: transform;
}

.pressable:active:not(:disabled) {
  transform: scale(0.972);
  transition-duration: 80ms;
}

@media (hover: hover) {
  .pressable:hover:not(:disabled) {
    opacity: 0.92;
  }
}

body.kb-open .tabbar {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
