:root {
  color-scheme: light;
  --ink: #17221d;
  --muted: #6f7b75;
  --paper: #fffef9;
  --line: #d8ded9;
  --excel: #217346;
  --left: #e65470;
  --right: #24b879;
}

* { box-sizing: border-box; }

html, body { width: 100%; height: 100%; height: 100dvh; }

body {
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 8%, #f6dce1 0, transparent 30%),
    radial-gradient(circle at 88% 90%, #ccebdc 0, transparent 32%),
    #f4f2ec;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

main {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-rows: 46px minmax(0, 1fr);
  gap: 7px;
  padding: 8px 14px 12px;
}

header {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 22px;
  padding: 0 6px;
}

h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(25px, 2.2vw, 36px);
  font-weight: 500;
  letter-spacing: -.04em;
}

.stats, .ranking-link { color: var(--muted); font-size: 13px; white-space: nowrap; }
.ranking-link { color: #a74a28; font-weight: 750; text-decoration: none; }
.ranking-link:hover, .ranking-link:focus-visible { text-decoration: underline; outline: none; }

.stage { min-height: 0; position: relative; }

.arrow {
  appearance: none;
  position: absolute;
  z-index: 4;
  top: 50%;
  width: 68px;
  padding: 0;
  border: 0;
  background: rgba(244, 242, 236, .74);
  color: #65726b;
  cursor: pointer;
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", Georgia, serif;
  font-size: clamp(40px, 4.5vw, 67px);
  font-weight: 300;
  line-height: .9;
  transform: translateY(-50%);
  transition: color 120ms ease, transform 120ms ease;
}

.arrow.left { left: 0; color: var(--left); border-radius: 0 18px 18px 0; }
.arrow.right { right: 0; color: #ef426f; border-radius: 18px 0 0 18px; }
.arrow.left:hover, .arrow.left:focus-visible { color: var(--left); transform: translateY(-50%) scale(1.08); outline: none; }
.arrow.right:hover, .arrow.right:focus-visible { color: var(--right); transform: translateY(-50%) scale(1.08); outline: none; }

.workbook {
  width: calc(100% - 92px);
  height: 100%;
  min-width: 0;
  margin: 0 auto;
  display: grid;
  grid-template-rows: 38px 28px minmax(0, 1fr) 29px;
  overflow: hidden;
  background: var(--paper);
  border: 1px solid rgba(23, 34, 29, .14);
  border-radius: 13px;
  box-shadow: 0 18px 52px rgba(35, 45, 39, .14);
  transition: opacity 125ms ease, transform 125ms ease;
}

.workbook.out-left { opacity: 0; transform: translateX(-48px) rotate(-.5deg); }
.workbook.out-right { opacity: 0; transform: translateX(48px) rotate(.5deg); }

.reactions {
  position: absolute;
  z-index: 8;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.reaction {
  position: absolute;
  left: 50%;
  top: 62%;
  opacity: 0;
  font-size: clamp(28px, 4vw, 62px);
  filter: drop-shadow(0 6px 7px rgba(57, 30, 35, .22));
  animation: reaction-burst 720ms cubic-bezier(.16, .72, .31, 1) var(--delay) both;
}

.reaction.like { color: #ef426f; }
.reaction.dislike { font-size: clamp(25px, 3.5vw, 54px); }

@keyframes reaction-burst {
  0% { opacity: 0; transform: translate(-50%, 0) scale(.35) rotate(0); }
  15% { opacity: 1; }
  75% { opacity: .96; }
  100% { opacity: 0; transform: translate(calc(-50% + var(--x)), var(--y)) scale(1.12) rotate(var(--r)); }
}

.workbook-titlebar {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 12px;
  border-bottom: 1px solid var(--line);
}

.identity { min-width: 0; display: flex; align-items: baseline; gap: 10px; }
.identity strong { max-width: 45vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.identity span { overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.source { color: var(--muted); font-size: 10px; letter-spacing: .12em; white-space: nowrap; }

.formula-bar {
  min-width: 0;
  display: grid;
  grid-template-columns: 58px 34px minmax(0, 1fr);
  align-items: center;
  background: #fafbf9;
  border-bottom: 1px solid #cfd6d1;
  color: #3e4943;
  font-size: 11px;
}

.cell-address, .fx { height: 100%; display: grid; place-items: center; border-right: 1px solid #cfd6d1; }
.fx { color: var(--excel); font-family: Georgia, serif; font-size: 15px; font-style: italic; }
.formula-value { min-width: 0; overflow: hidden; padding: 0 8px; text-overflow: ellipsis; white-space: nowrap; }

.sheet-frame { min-height: 0; overflow: hidden; background: white; }

.sheet-grid {
  width: 100%;
  height: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  background: white;
  font-family: "Cascadia Mono", Consolas, "Liberation Mono", monospace;
  font-size: clamp(7px, .55vw, 10px);
}

.sheet-grid th, .sheet-grid td {
  min-width: 0;
  max-width: 0;
  overflow: hidden;
  padding: 1px 3px;
  border: 1px solid #d9dfda;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.05;
}

.sheet-grid td { white-space: nowrap !important; }

.sheet-grid thead th, .row-head, .corner {
  background: #f1f3f1 !important;
  color: #506057 !important;
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  font-weight: 500 !important;
  text-align: center !important;
}

.sheet-grid thead th { border-bottom-color: #bcc8c0; }
.row-head { width: 38px; border-right-color: #bcc8c0 !important; }
.corner { width: 38px; }
.sheet-grid td { cursor: default; }
.sheet-grid td.selected { position: relative; overflow: visible; outline: 2px solid var(--excel); outline-offset: -2px; z-index: 2; }

.sheet-tabs {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0 9px;
  background: #f5f6f4;
  border-top: 1px solid #cfd6d1;
  color: #526058;
  font-size: 10px;
}

.sheet-nav { color: #6c7871; font-size: 18px; line-height: 1; }
#sheet-tabs { min-width: 0; display: flex; align-self: stretch; overflow: hidden; }
.sheet-tab { max-width: 150px; display: flex; align-items: center; padding: 0 15px; overflow: hidden; background: white; border-bottom: 2px solid var(--excel); text-overflow: ellipsis; white-space: nowrap; }
.sheet-tab.inactive { background: transparent; border-bottom-color: transparent; }
.vote-hint { margin-left: auto; color: var(--muted); white-space: nowrap; }
.bad { color: var(--left); } .good { color: var(--right); }

.ranking-dialog {
  width: min(780px, 92vw);
  max-height: 84vh;
  padding: 0;
  overflow: hidden;
  color: var(--ink);
  background: var(--paper);
  border: 0;
  border-radius: 20px;
  box-shadow: 0 28px 90px rgba(20, 32, 25, .28);
}

.ranking-dialog::backdrop { background: rgba(20, 28, 24, .58); backdrop-filter: blur(5px); }
.ranking-head { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px 14px; border-bottom: 1px solid var(--line); }
.ranking-head h2 { margin: 0; font-family: Georgia, serif; font-size: 30px; font-weight: 500; }
.ranking-close { appearance: none; padding: 0; color: var(--muted); background: transparent; border: 0; cursor: pointer; font-size: 32px; }
.ranking-list { max-height: calc(84vh - 70px); margin: 0; padding: 8px 24px 20px; overflow: auto; list-style: none; }
.ranking-row { display: grid; grid-template-columns: 34px 126px minmax(0, 1fr) auto; align-items: center; gap: 13px; padding: 11px 0; border-bottom: 1px solid #edf0ed; }
.ranking-number { color: #b34d27; font-family: Georgia, serif; font-size: 24px; }
.ranking-preview-link { display: block; border-radius: 6px; color: inherit; text-decoration: none; outline-offset: 3px; }
.ranking-preview {
  width: 126px;
  height: 72px;
  display: block;
  overflow: hidden;
  background: white;
  border: 1px solid #cfd7d1;
  border-radius: 6px;
  box-shadow: 0 3px 10px rgba(30, 45, 36, .08);
}
.ranking-preview table { width: 100%; height: 100%; table-layout: fixed; border-collapse: collapse; font: 3.5px/1 "Cascadia Mono", Consolas, monospace; }
.ranking-preview td { max-width: 0; overflow: hidden; padding: 0 1px; border: 1px solid #dfe4e0; text-overflow: clip; white-space: nowrap !important; }
.ranking-identity { min-width: 0; }
.ranking-name { display: block; overflow: hidden; color: var(--ink); font-weight: 700; text-decoration: underline; text-decoration-color: #c5cec8; text-underline-offset: 3px; text-overflow: ellipsis; white-space: nowrap; }
.ranking-name:hover, .ranking-name:focus-visible { color: #a74a28; text-decoration-color: currentColor; outline: none; }
.ranking-meta, .ranking-empty { margin-top: 3px; color: var(--muted); font-size: 12px; }
.ranking-score { color: #2b8f63; font-weight: 800; white-space: nowrap; }

@media (max-width: 720px) {
  main { padding: 4px; gap: 4px; grid-template-rows: 36px minmax(0, 1fr); }
  header { grid-template-columns: 1fr auto; gap: 8px; }
  h1 { font-size: clamp(22px, 7vw, 29px); }
  header .stats { display: none; }
  .workbook { width: 100%; border-radius: 9px; grid-template-rows: 34px 25px minmax(0, 1fr) 25px; }
  .workbook { touch-action: none; user-select: none; }
  .arrow { z-index: 6; width: 43px; font-size: 32px; background: rgba(244, 242, 236, .7); }
  .arrow.left { left: -4px; }
  .arrow.right { right: -4px; }
  .identity span, .source, .vote-hint { display: none; }
  .identity strong { max-width: 78vw; font-size: 10px; }
  .sheet-grid { font-size: 6.5px; }
  .sheet-grid th, .sheet-grid td { padding: 1px 2px; }
  .row-head, .corner { width: 25px; }
  .formula-bar { grid-template-columns: 48px 28px minmax(0, 1fr); font-size: 9px; }
  .sheet-tabs { padding: 0 5px; }
  .sheet-tab { max-width: 105px; padding: 0 9px; }
  .ranking-dialog { width: 96vw; max-height: 90dvh; border-radius: 14px; }
  .ranking-head { padding: 14px 15px 10px; }
  .ranking-head h2 { font-size: 23px; }
  .ranking-list { max-height: calc(90dvh - 58px); padding: 5px 15px 14px; }
  .ranking-row { grid-template-columns: 24px 92px minmax(0, 1fr); gap: 7px; padding: 9px 0; }
  .ranking-number { font-size: 20px; }
  .ranking-preview { width: 92px; height: 58px; }
  .ranking-score { grid-column: 3; font-size: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .reaction { animation-duration: 1ms; }
  .workbook { transition-duration: 1ms; }
}
