/* App layer on top of design-system/gruprank.css. Use its --gr-* tokens only. */

:root {
  --tap: 44px;
  --tabs-h: 49px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --overlay-shadow: 0 16px 48px rgb(0 0 0 / 0.18);
  -webkit-text-size-adjust: 100%;
}

html { background: var(--gr-bg); }
body { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
main { flex: 1 0 auto; }
body > .gr-wrap { width: 100%; }
[hidden] { display: none !important; }
p { margin: 0; }
b, strong { font-weight: 600; }
.center { text-align: center; }
.accent-text { color: var(--gr-link); }

.icon {
  width: 20px; height: 20px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round;
}

.skip-link { position: absolute; left: 16px; top: -100px; z-index: 100; }
.skip-link:focus { top: 12px; }

/* ----------------------------------------------------------------- header */

.site-header { border-bottom: 1px solid var(--gr-border); padding-top: env(safe-area-inset-top); }
.nav { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 72px; }
.brand { display: inline-flex; align-items: center; flex: none; border-radius: 4px; }
.brand img { display: block; width: 176px; height: auto; }
.logo-dark { display: none !important; }
[data-theme="dark"] .logo-dark { display: block !important; }
[data-theme="dark"] .logo-light { display: none !important; }
.nav-right { display: flex; align-items: center; gap: 8px; }
.theme-toggle { min-width: var(--tap); padding-inline: 10px; }

.board-head { padding-top: 32px; }
.board-title {
  font-size: 44px; line-height: 1.08; letter-spacing: -0.04em; font-weight: 600;
  overflow-wrap: anywhere;
}
.board-meta {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px;
  margin-top: 16px; font-size: 14px; color: var(--gr-muted);
}
.meta-item { display: inline-flex; align-items: center; gap: 6px; }
.meta-item .icon { width: 16px; height: 16px; }

.tabs-bar { position: sticky; top: 0; z-index: 20; margin-top: 24px; background: var(--gr-bg); }
.board-tabs { gap: clamp(16px, 5vw, 32px); }
.board-tabs a {
  flex: none; display: inline-flex; align-items: center;
  min-height: 48px; margin-bottom: -1px; padding: 12px 0;
  border-bottom: 2px solid transparent;
  color: var(--gr-muted); font-size: 14px; font-weight: 500; text-decoration: none;
  transition: color var(--gr-fast) var(--gr-ease);
}
.board-tabs a:hover { color: var(--gr-text); }
.board-tabs a[aria-current="page"] { color: var(--gr-text); font-weight: 600; border-bottom-color: var(--gr-link); }

.footer { display: flex; align-items: center; gap: 16px; margin-top: 64px; padding-block: 32px calc(32px + var(--safe-b)); border-top: 1px solid var(--gr-border); }

@media (max-width: 600px) {
  .nav { min-height: 64px; gap: 8px; }
  .nav-right { gap: 4px; }
  .brand img { width: 144px; }
  .board-head { padding-top: 24px; }
  .board-title { font-size: 36px; }
  .footer { margin-top: 48px; }
}
@media (max-width: 400px) { .hide-xs { display: none; } }

/* ----------------------------------------------------------------- layout */

.page { display: flex; flex-direction: column; gap: 32px; padding-top: 32px; }
.page > * { width: 100%; max-width: 760px; }
.page.wide > *, .page.home > * { max-width: none; }
.page.centered { padding-top: 48px; }
.page h2 { font-size: 20px; line-height: 1.2; letter-spacing: -0.025em; }
.page h3 { font-size: 16px; line-height: 1.3; letter-spacing: -0.015em; }
.card-title { font-size: 24px; line-height: 1.2; letter-spacing: -0.03em; }

.stack { display: flex; flex-direction: column; gap: 16px; }
.narrow { max-width: 440px !important; margin-inline: auto; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.gr-card.pad { padding: 24px; }
@media (max-width: 600px) { .gr-card.pad { padding: 20px 16px; } }

.notice {
  padding: 12px 16px; border: 1px solid var(--gr-border); border-radius: var(--gr-radius-control);
  background: var(--gr-surface); font-size: 14px;
}
.notice.error { color: var(--gr-error); border-color: currentColor; background: var(--gr-bg); }
.empty {
  padding: 24px; border-radius: var(--gr-radius-card); background: var(--gr-surface);
  color: var(--gr-muted); font-size: 14px; text-align: center;
}

/* --------------------------------------------------------------- controls */

.field { display: flex; flex-direction: column; gap: 8px; font-size: 14px; font-weight: 500; }
.field .hint { margin-top: -6px; color: var(--gr-muted); font-weight: 400; }
.gr-input { font-size: 16px; letter-spacing: -0.01em; transition: border-color var(--gr-fast) var(--gr-ease); }
.gr-input::placeholder { color: var(--gr-muted); opacity: 1; }
textarea.gr-input { resize: vertical; }

.select { position: relative; display: block; min-width: 0; }
.select select { appearance: none; -webkit-appearance: none; padding-right: 40px; text-overflow: ellipsis; }
.select::after {
  content: ""; position: absolute; right: 12px; top: 50%; width: 20px; height: 20px;
  transform: translateY(-50%) rotate(90deg); pointer-events: none; background: var(--gr-muted);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none' stroke='black' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M8 5l5 5-5 5'/%3E%3C/svg%3E") center / 20px no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none' stroke='black' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M8 5l5 5-5 5'/%3E%3C/svg%3E") center / 20px no-repeat;
}

.gr-btn { white-space: nowrap; user-select: none; -webkit-user-select: none; }
.gr-btn.block { width: 100%; }
.gr-btn.icon-btn { width: var(--tap); padding: 0; }
.gr-btn.danger { color: var(--gr-error); }
.file-btn { position: relative; cursor: pointer; }
.file-btn:has(input:focus-visible),
.photo-pick:has(input:focus-visible),
.chip:has(input:focus-visible) { outline: 2px solid var(--gr-focus); outline-offset: 3px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; border: 0; min-width: 0; }
.chips form { margin: 0; }
.chip {
  position: relative; display: inline-flex; align-items: center; gap: 8px;
  min-height: var(--tap); padding: 0 14px;
  border: 1px solid var(--gr-control-border); border-radius: var(--gr-radius-control);
  background: var(--gr-bg); color: var(--gr-text);
  font-size: 14px; font-weight: 500; cursor: pointer; user-select: none; -webkit-user-select: none;
  transition: background var(--gr-fast) var(--gr-ease);
}
.chip:hover { background: var(--gr-surface); }
.chip small { color: var(--gr-muted); font-size: 12px; font-weight: 500; font-variant-numeric: tabular-nums; }
.chip .check { display: none; width: 16px; height: 16px; color: var(--gr-link); margin-left: -4px; }
.chip.on { background: var(--gr-selected); border-color: var(--gr-link); }
.chip.on .check { display: block; }

.tags { display: flex; flex-wrap: wrap; gap: 8px; }
.tag {
  display: inline-flex; align-items: center; padding: 4px 10px 4px 4px;
  border: 1px solid var(--gr-border); border-radius: var(--gr-radius-control); font-size: 14px;
}

.segmented {
  display: inline-flex; gap: 2px; padding: 2px;
  border: 1px solid var(--gr-control-border); border-radius: var(--gr-radius-control);
}
.segmented label { position: relative; display: block; }
.segmented input { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: pointer; }
.segmented span {
  display: flex; align-items: center; min-height: 38px; padding: 0 12px; border-radius: 6px;
  color: var(--gr-muted); font-size: 14px; font-weight: 500;
}
.segmented input:checked + span { background: var(--gr-selected); color: var(--gr-text); font-weight: 600; }
.segmented input:focus-visible + span { outline: 2px solid var(--gr-focus); outline-offset: 2px; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); z-index: 50;
  max-width: calc(100% - 32px); padding: 12px 16px;
  border-radius: var(--gr-radius-control); background: var(--gr-text); color: var(--gr-bg);
  box-shadow: var(--overlay-shadow);
  font-size: 14px; font-weight: 500;
  transform: translate(-50%, 8px); opacity: 0; pointer-events: none;
  transition: opacity var(--gr-normal) var(--gr-ease), transform var(--gr-normal) var(--gr-ease);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.mobile-only { display: none !important; }
@media (pointer: coarse) {
  .mobile-only { display: inline-flex !important; }
  .desktop-only { display: none !important; }
}

/* ------------------------------------------------------------------ lists */

.list { list-style: none; margin: 0; padding: 0; }
.rule-list > li + li { border-top: 1px solid var(--gr-border); }
.row-link {
  display: flex; align-items: center; gap: 16px; min-height: 56px;
  color: var(--gr-text); font-weight: 500; text-decoration: none;
}
.row-link .row-title { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.row-link:hover .row-title { text-decoration: underline; text-underline-offset: 4px; }
.row-link .chev { margin-left: auto; color: var(--gr-muted); }
.plain-row { display: flex; align-items: center; gap: 12px; min-height: 52px; }

.thumb {
  flex: none; display: inline-grid; place-items: center;
  width: 40px; height: 40px; border-radius: var(--gr-radius-control);
  border: 1px solid var(--gr-border); background: var(--gr-surface); object-fit: cover;
  color: var(--gr-muted); font-size: 14px; font-weight: 600;
}
.thumb.sm { width: 28px; height: 28px; border-radius: 6px; font-size: 12px; }
.thumb.xs { width: 22px; height: 22px; border-radius: 5px; font-size: 11px; }
.thumb.lg { width: 140px; height: 140px; border-radius: var(--gr-radius-card); font-size: 40px; }
.item-label { display: inline-flex; align-items: center; gap: 10px; min-width: 0; }
.item-name { min-width: 0; overflow-wrap: anywhere; }
.rank-num { font-weight: 600; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------- mine */

.share-card { background: var(--gr-surface); }
.copy-row { display: flex; gap: 8px; }
.copy-row .gr-input { flex: 1; min-width: 0; }

.add-form { position: sticky; top: var(--tabs-h); z-index: 10; margin-block: -12px; padding-block: 12px; background: var(--gr-bg); }
.add-row { display: flex; gap: 8px; }
.add-row .gr-input { flex: 1; min-width: 0; }
.photo-pick { position: relative; flex: none; border-radius: var(--gr-radius-control); cursor: pointer; }
.photo-preview {
  display: grid; place-items: center; width: var(--tap); height: var(--tap); overflow: hidden;
  border: 1px solid var(--gr-control-border); border-radius: var(--gr-radius-control);
  background: var(--gr-bg); color: var(--gr-muted);
  transition: background var(--gr-fast) var(--gr-ease);
}
.photo-pick:hover .photo-preview { background: var(--gr-surface); }
.photo-preview img { width: 100%; height: 100%; object-fit: cover; }

.rank-list { display: flex; flex-direction: column; min-height: 8px; }
.rank-list:empty { min-height: 0; }
.rank-list:empty + .empty { margin-top: -16px; }
.rank-list:not(:empty) + .empty { display: none; }
.rank-row {
  display: flex; align-items: center; gap: 4px;
  min-height: 64px; padding: 8px 0;
  border-bottom: 1px solid var(--gr-border); background: var(--gr-bg);
}
.rank-row:first-child { border-top: 1px solid var(--gr-border); }
.handle {
  flex: none; display: grid; place-items: center; width: 36px; height: var(--tap);
  padding: 0; border: 0; border-radius: var(--gr-radius-control); background: none;
  color: var(--gr-muted); cursor: grab; touch-action: none;
}
.handle:hover { color: var(--gr-text); background: var(--gr-surface); }
.rank-row .pos {
  flex: none; width: 28px; margin-right: 8px;
  color: var(--gr-muted); font-size: 14px; font-variant-numeric: tabular-nums;
}
.unranked .rank-row .pos { display: none; }
.unranked .rank-row .handle { width: 28px; }
.row-body {
  flex: 1; min-width: 0; min-height: var(--tap); display: flex; align-items: center; gap: 12px;
  padding: 0; border: 0; border-radius: var(--gr-radius-control); background: none;
  color: inherit; text-align: left;
}
.row-body .item-name { font-size: 16px; font-weight: 500; }
.row-action { flex: none; color: var(--gr-muted); }
.row-action:hover { color: var(--gr-text); }
.drag-ghost { opacity: 0.4; }
.drag-chosen { background: var(--gr-raised); box-shadow: var(--overlay-shadow); }
.save-state { font-size: 14px; color: var(--gr-muted); }
.save-state.error { color: var(--gr-error); }

/* ----------------------------------------------------------------- sheets */

.sheet {
  width: 100%; max-width: 480px; padding: 24px;
  border: 1px solid var(--gr-border); border-radius: var(--gr-radius-card);
  background: var(--gr-raised); color: var(--gr-text); box-shadow: var(--overlay-shadow);
}
.sheet::backdrop { background: rgb(0 0 0 / 0.45); }
@media (max-width: 759px) {
  .sheet {
    max-width: none; max-height: 90dvh; margin: auto 0 0;
    border-radius: var(--gr-radius-card) var(--gr-radius-card) 0 0;
    padding-bottom: calc(24px + var(--safe-b));
  }
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sheet-image { display: flex; justify-content: center; }
.sheet-image.busy { opacity: 0.4; }
.photo-buttons { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.sheet-actions { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; }
.sheet-actions > :last-child { margin-left: auto; }

/* ----------------------------------------------------------------- tables */

.table-wrap {
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  border: 1px solid var(--gr-border); border-radius: var(--gr-radius-card);
}
.grid { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 14px; }
.grid th, .grid td {
  padding: 12px 16px; border-bottom: 1px solid var(--gr-border);
  text-align: left; vertical-align: middle; font-weight: 400;
}
.grid tbody tr:last-child > * { border-bottom: 0; }
.grid thead th {
  background: var(--gr-surface); color: var(--gr-muted);
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.grid td { min-width: 150px; max-width: 260px; }
.grid .sticky { position: sticky; left: 0; z-index: 1; max-width: 46vw; background: var(--gr-bg); border-right: 1px solid var(--gr-border); }
.grid thead .sticky { z-index: 2; background: var(--gr-surface); }
.grid th.num, .grid td.num { min-width: 72px; text-align: right; font-variant-numeric: tabular-nums; }
.grid th.rank-num { color: var(--gr-muted); font-weight: 400; }
.grid.compare tbody th { min-width: 160px; }
.grid.compare tr.match > * { background: var(--gr-selected); }
.grid.compare .diff { color: var(--gr-muted); white-space: nowrap; }
.grid.compare tr.far .diff { color: var(--gr-text); font-weight: 600; }

/* ---------------------------------------------------------------- compare */

.compare-pick { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; }
.vs { color: var(--gr-muted); font-size: 14px; font-weight: 500; }
.stats {
  display: grid; grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--gr-border); border-radius: var(--gr-radius-card);
}
.stat { display: flex; flex-direction: column; gap: 4px; padding: 16px; min-width: 0; }
.stat + .stat { border-left: 1px solid var(--gr-border); }
.stat-num { font-size: 28px; line-height: 1.1; font-weight: 600; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.stat-label { color: var(--gr-muted); font-size: 12px; }
@media (max-width: 600px) { .stat { padding: 12px; } .stat-num { font-size: 22px; } }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.bar { display: block; height: 6px; overflow: hidden; border-radius: 3px; background: var(--gr-border); }
.bar > span { display: block; height: 100%; background: var(--gr-muted); }
.pairs .row-title { flex: 1.4; }
.pairs .bar { flex: 1; }
.pair-score { width: 48px; text-align: right; }

/* ---------------------------------------------------------- group ranking */

.table-label {
  display: flex; justify-content: space-between; padding: 0 16px 12px;
  color: var(--gr-muted); font-size: 12px;
}
.group-row {
  display: grid; grid-template-columns: 32px auto minmax(0, 1fr) auto; align-items: center; gap: 16px;
  padding: 16px; border-top: 1px solid var(--gr-border);
}
.group-row.top { background: var(--gr-selected); border-radius: var(--gr-radius-control); border-top-color: transparent; }
.group-row.top + .group-row { border-top-color: transparent; }
.rank-number { color: var(--gr-muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.group-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.group-body .item-name { font-size: 16px; font-weight: 500; }
.group-body .sub { color: var(--gr-muted); font-size: 12px; }
.score { font-size: 18px; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.score-max { display: block; color: var(--gr-muted); font-size: 11px; font-weight: 400; }
.method { padding-inline: 16px; max-width: 600px; line-height: 1.7; }
@media (max-width: 600px) {
  .group-row { gap: 10px; padding: 14px 12px; grid-template-columns: 24px auto minmax(0, 1fr) auto; }
  .table-label, .method { padding-inline: 12px; }
}

/* ------------------------------------------------------------------ graph */

.graph-controls { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; }
.plot-wrap { width: 100%; max-width: 560px; margin-inline: auto; }
.plot {
  position: relative; width: 100%; aspect-ratio: 1 / 1; overflow: visible;
  border: 1px solid var(--gr-control-border); border-radius: var(--gr-radius-card);
  background-color: var(--gr-bg);
  background-image:
    linear-gradient(var(--gr-surface) 1px, transparent 1px),
    linear-gradient(90deg, var(--gr-surface) 1px, transparent 1px);
  background-size: 12.5% 12.5%;
  user-select: none; -webkit-user-select: none;
}
.plot.editable { cursor: crosshair; }
.axis-line { position: absolute; background: var(--gr-border); pointer-events: none; }
.axis-line.h { left: 0; right: 0; top: 50%; height: 1px; }
.axis-line.v { top: 0; bottom: 0; left: 50%; width: 1px; }
.plot .axis-label {
  position: absolute; z-index: 3; min-height: 0; padding: 2px 6px;
  border: 1px solid transparent; border-radius: 6px; background: var(--gr-bg);
  color: var(--gr-muted); font-size: 16px; font-weight: 500; text-align: center;
}
.plot .axis-label:hover { border-color: var(--gr-control-border); }
.plot .axis-label:focus { color: var(--gr-text); border-color: var(--gr-control-border); }
.axis-label.top { top: 6px; left: 50%; transform: translateX(-50%); width: 46%; }
.axis-label.bottom { bottom: 6px; left: 50%; transform: translateX(-50%); width: 46%; }
.axis-label.left { left: 6px; top: 50%; transform: translateY(-50%); width: 26%; text-align: left; }
.axis-label.right { right: 6px; top: 50%; transform: translateY(-50%); width: 26%; text-align: right; }
.dots { position: absolute; inset: 0; z-index: 4; pointer-events: none; }
.dot { position: absolute; width: 0; height: 0; pointer-events: auto; touch-action: none; }
.plot.editable .dot { cursor: grab; }
.dot .dot-img {
  position: absolute; left: 0; top: 0; transform: translate(-50%, -50%);
  width: 36px; height: 36px; border-radius: 50%; border: 2px solid var(--gr-text); background: var(--gr-bg);
}
.dot .dot-label {
  position: absolute; left: 0; top: 20px; transform: translateX(-50%);
  max-width: 120px; padding: 1px 5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  border-radius: 4px; background: var(--gr-bg); color: var(--gr-text); font-size: 12px; font-weight: 600;
}
.dot .dot-label small { color: var(--gr-muted); font-weight: 500; }
.dot.selected .dot-img { outline: 3px solid var(--gr-link); outline-offset: 2px; }
.dot.dragging { z-index: 10; cursor: grabbing; }
.dot.dragging .dot-img { transform: translate(-50%, -50%) scale(1.15); }
.dot.faint .dot-img { width: 28px; height: 28px; border-width: 1px; border-color: var(--gr-muted); }
.dot.faint .dot-label { top: 15px; font-size: 11px; }
.dot.ghost { z-index: 100; pointer-events: none; opacity: 0.85; }
.selected-bar {
  display: flex; align-items: center; gap: 4px; padding: 4px 4px 4px 16px;
  border: 1px solid var(--gr-border); border-radius: var(--gr-radius-control); background: var(--gr-surface);
}
.selected-bar span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.tray-chip { padding-left: 8px; }

/* ------------------------------------------------------------------- home */

.home-hero {
  display: grid; grid-template-columns: 1.1fr 1fr; gap: 80px; align-items: center;
  padding-block: 48px 32px;
}
.home-hero .display { margin-top: 24px; }
.lead { margin-top: 24px; max-width: 465px; font-size: 18px; line-height: 1.6; letter-spacing: -0.01em; }
.create-form { max-width: 480px; justify-self: end; width: 100%; }
.your-boards { max-width: 760px; }
.how { padding-top: 64px; border-top: 1px solid var(--gr-border); }
.page .section-title { margin-top: 20px; font-size: 36px; line-height: 1.1; letter-spacing: -0.04em; }
.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 48px; margin-top: 48px; }
.step-no { display: block; margin-bottom: 16px; color: var(--gr-link); font-size: 12px; font-weight: 600; }
.page .steps h3 { font-size: 20px; letter-spacing: -0.025em; }
.steps p { margin-top: 12px; max-width: 310px; font-size: 14px; line-height: 1.7; }
@media (max-width: 900px) {
  .home-hero { gap: 40px; }
  .steps { gap: 24px; }
}
@media (max-width: 760px) {
  .home-hero { grid-template-columns: 1fr; padding-block: 24px 0; }
  .create-form { justify-self: stretch; max-width: none; }
  .how { padding-top: 48px; }
  .page .section-title { font-size: 30px; }
  .steps { grid-template-columns: 1fr; gap: 32px; margin-top: 32px; }
  .step-no { margin-bottom: 8px; }
}
