:root {
  --ink: #18130e;
  --paper: #fff6cc;
  --paper-strong: #ffe6ad;
  --line: #9d7745;
  --leaf: #7bc86c;
  --leaf-dark: #39924e;
  --sky: #6fd4ef;
  --orange: #ffb248;
  --orange-dark: #d9751e;
  --gray: #e6e6e6;
  --danger: #c7352d;
  --good: #197a45;
  --shadow: #14100d;
  color-scheme: light;
  font-family:
    "Hiragino Kaku Gothic ProN",
    "Yu Gothic",
    "Meiryo",
    system-ui,
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background:
    linear-gradient(#6ed7f0 0 62%, #55bd64 62% 100%);
  letter-spacing: 0;
}

button,
textarea,
code {
  font: inherit;
  letter-spacing: 0;
}

button {
  touch-action: manipulation;
}

.game-shell {
  width: min(100%, 460px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: 14px 12px 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.18), transparent 18%, transparent 82%, rgba(0, 0, 0, 0.08)),
    transparent;
}

.paper-panel,
.race-banner,
.intro-card {
  border: 4px solid var(--ink);
  border-radius: 8px;
  background: var(--paper);
  box-shadow:
    0 4px 0 var(--shadow),
    inset 0 0 0 3px #f6c982;
}

.paper-panel {
  padding: 12px;
}

.center-panel {
  margin: auto 0;
  text-align: center;
}

.screen-kicker {
  margin: 0 0 4px;
  font-size: 0.82rem;
  font-weight: 800;
  color: #5d3c1d;
}

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

h1,
h2 {
  line-height: 1.12;
}

h1 {
  margin-bottom: 10px;
  font-size: 2.45rem;
  text-align: center;
  text-shadow: 2px 2px 0 #fff, 4px 4px 0 rgba(0, 0, 0, 0.2);
}

h2 {
  margin-bottom: 10px;
  font-size: 1.35rem;
}

h3 {
  margin-bottom: 6px;
  font-size: 1rem;
}

p {
  line-height: 1.55;
}

.small-note,
.disclaimer {
  font-size: 0.8rem;
}

.title-screen {
  position: relative;
  min-height: calc(100dvh - 36px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
}

.debug-unlock-button {
  position: absolute;
  display: block;
  left: 0;
  bottom: 0;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  opacity: 0;
  cursor: default;
}

.title-art {
  width: 138px;
  height: 138px;
  display: grid;
  place-items: center;
  border: 4px solid var(--ink);
  border-radius: 6px;
  background: #562520;
  box-shadow: 0 5px 0 var(--shadow);
  overflow: hidden;
}

.title-art img {
  width: 100%;
  height: 100%;
  border-radius: 2px;
  object-fit: cover;
  image-rendering: pixelated;
}

.title-copy {
  max-width: 320px;
  margin-bottom: 6px;
  font-weight: 800;
}

.record-summary-button {
  width: min(100%, 330px);
  padding: 8px 10px;
  border: 3px solid var(--ink);
  border-radius: 8px;
  background: #fffbe6;
  box-shadow: 0 3px 0 var(--shadow);
  color: var(--ink);
  font-weight: 900;
  cursor: pointer;
}

.record-summary-button span {
  display: block;
  color: #477046;
  font-size: 0.78rem;
}

.record-summary-button strong {
  display: block;
  margin-top: 2px;
  font-size: 1rem;
}

.menu-stack,
.action-row,
.bottom-actions {
  display: flex;
  gap: 12px;
}

.menu-stack {
  width: min(100%, 330px);
  flex-direction: column;
}

.sister-site-panel {
  width: min(100%, 360px);
  padding: 8px;
  border: 4px solid var(--ink);
  border-radius: 8px;
  background: #fff6cc;
  box-shadow: 0 4px 0 var(--shadow);
}

.sister-site-panel p {
  margin: 0 0 6px;
  color: #5d3c1d;
  font-size: 0.78rem;
  font-weight: 950;
}

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

.sister-site-link {
  min-width: 0;
  min-height: 58px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-areas:
    "icon label"
    "icon status";
  place-items: center;
  gap: 1px 6px;
  padding: 6px 7px;
  border: 3px solid var(--ink);
  border-radius: 6px;
  color: var(--ink);
  background: #fffbe6;
  box-shadow: 0 3px 0 var(--shadow);
  text-decoration: none;
  font-weight: 950;
}

.sister-site-link img {
  grid-area: icon;
  width: 32px;
  height: 32px;
  border: 2px solid var(--ink);
  border-radius: 4px;
  object-fit: cover;
}

.sister-site-link span {
  grid-area: label;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.74rem;
}

.sister-site-link small {
  grid-area: status;
  color: #477046;
  font-size: 0.58rem;
  font-weight: 950;
}

.action-row,
.bottom-actions {
  align-items: center;
  justify-content: center;
}

.bottom-actions {
  position: sticky;
  bottom: 8px;
  z-index: 5;
  padding-top: 2px;
}

.bottom-actions .pixel-button {
  flex: 1 1 0;
}

.ticket-bottom-actions {
  gap: 8px;
}

.ticket-bottom-actions .pixel-button {
  min-height: 60px;
}

.pixel-button,
.sheet-choice,
.number-choice,
.tab-button,
.icon-button,
.details-toggle {
  border: 3px solid var(--ink);
  border-radius: 8px;
  color: var(--ink);
  background: var(--gray);
  box-shadow: 0 4px 0 var(--shadow);
  font-weight: 900;
  cursor: pointer;
}

.pixel-button {
  min-height: 52px;
  padding: 10px 18px;
  background: var(--orange);
  box-shadow: 0 4px 0 var(--orange-dark), 0 7px 0 var(--shadow);
  font-size: 1.15rem;
}

.pixel-button.back-button {
  flex: 0 0 52px;
  min-width: 52px;
  padding-inline: 0;
  font-size: 1.35rem;
}

.pixel-button.reset-ticket-button {
  flex: 0 1 92px;
  min-width: 76px;
  display: grid;
  place-items: center;
  gap: 0;
  padding-inline: 8px;
  font-size: 0.82rem;
  line-height: 1.05;
}

.pixel-button.primary {
  background: var(--orange);
  box-shadow: 0 4px 0 var(--orange-dark), 0 7px 0 var(--shadow);
}

.pixel-button.cart-button {
  flex: 0 0 56px;
  min-width: 56px;
  padding-inline: 0;
  font-size: 1.35rem;
}

.pixel-button.purchase-button {
  flex: 1 1 72px;
  min-width: 64px;
}

.pixel-button.secondary {
  background: var(--orange);
  box-shadow: 0 4px 0 var(--orange-dark), 0 7px 0 var(--shadow);
}

.title-screen .pixel-button:not(.primary) {
  background: #fff;
  box-shadow: 0 4px 0 var(--shadow);
}

.pixel-button:disabled {
  color: #665f59;
  background: #d7d7d7;
  box-shadow: 0 3px 0 #9c9c9c;
  cursor: not-allowed;
}

.pixel-button:not(:disabled):active,
.sheet-choice:not(:disabled):active,
.number-choice:not(:disabled):active,
.tab-button:not(:disabled):active,
.icon-button:not(:disabled):active,
.details-toggle:not(:disabled):active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--shadow);
}

.danger-panel {
  background: #ffe0d8;
}

.danger-text {
  color: var(--danger);
}

.plus-text {
  color: var(--good);
}

.race-banner {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-areas:
    "count title title"
    "meta meta money";
  align-items: center;
  gap: 2px 10px;
  padding: 10px 12px;
  background: #fff4d4;
}

.race-count {
  grid-area: count;
  padding: 0;
  border: 0;
  color: inherit;
  background: transparent;
  box-shadow: none;
  font-size: 1rem;
  font-weight: 900;
  text-align: left;
}

.race-title {
  grid-area: title;
  min-width: 0;
  font-size: clamp(0.82rem, calc(2rem - var(--race-title-length, 8) * 0.08rem), 1.55rem);
  font-weight: 950;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
}

.race-meta {
  grid-area: meta;
  min-width: 0;
  font-weight: 800;
  text-align: center;
  white-space: nowrap;
}

.money-badge {
  grid-area: money;
  align-self: start;
  min-width: 108px;
  max-width: 154px;
  padding: 6px;
  border: 3px solid var(--ink);
  border-radius: 6px;
  background: #f6fff1;
  font-weight: 900;
  text-align: center;
}

.money-badge span,
.money-badge small {
  display: block;
  font-size: 0.66rem;
  line-height: 1.15;
  color: #477046;
}

.money-badge strong {
  display: block;
  font-size: clamp(0.58rem, calc(1.08rem - var(--money-length, 8) * 0.028rem), 0.82rem);
  line-height: 1.2;
  white-space: nowrap;
}

.intro-screen {
  min-height: calc(100dvh - 38px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  text-align: center;
}

.intro-card {
  width: min(100%, 360px);
  padding: 18px 12px;
}

.intro-card h2 {
  font-size: 2rem;
}

.roughness {
  display: inline-flex;
  margin-top: 8px;
  padding: 6px 12px;
  border: 3px solid var(--ink);
  border-radius: 6px;
  font-weight: 900;
}

.roughness.solid {
  background: #d7f8b8;
}

.roughness.normal {
  background: #f8e7a2;
}

.roughness.rough {
  background: #ffd0bc;
}

.race-panel {
  padding: 8px;
}

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: #fff9d9;
}

.horse-table {
  min-width: 430px;
  table-layout: fixed;
  font-size: 0.82rem;
}

.compact-table {
  min-width: 350px;
}

th,
td {
  border: 1px solid rgba(93, 60, 29, 0.28);
  padding: 5px 4px;
  vertical-align: middle;
}

th {
  background: #99d57c;
  font-weight: 900;
}

.horse-table th:nth-child(1),
.horse-table td:nth-child(1) {
  width: 44px;
  text-align: center;
}

.horse-table th:nth-child(2),
.horse-table td:nth-child(2) {
  width: 132px;
}

.compact-table th:nth-child(2),
.compact-table td:nth-child(2) {
  width: 160px;
}

.horse-table th:nth-child(3),
.horse-table td:nth-child(3) {
  width: 44px;
  text-align: center;
}

.horse-table th:nth-child(4),
.horse-table td:nth-child(4) {
  width: 66px;
  text-align: center;
}

.horse-table th:nth-child(5),
.horse-table td:nth-child(5) {
  width: 72px;
  text-align: center;
}

.horse-table th:nth-child(6),
.horse-table td:nth-child(6),
.horse-table th:nth-child(7),
.horse-table td:nth-child(7) {
  width: 48px;
  text-align: center;
}

.horse-number {
  display: inline-grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border: 2px solid rgba(0, 0, 0, 0.25);
  border-radius: 4px;
  font-weight: 950;
}

.num-1 { background: #fff; }
.num-2 { color: #fff; background: #343434; }
.num-3 { color: #fff; background: #df4242; }
.num-4 { color: #fff; background: #3b74d7; }
.num-5 { background: #ffd946; }
.num-6 { background: #58bf68; }
.num-7 { background: #f08e3f; }
.num-8 { background: #f08e3f; }
.num-9 { background: #f29bc1; }
.num-10 { background: #f29bc1; }

.horse-name-button {
  width: 100%;
  min-height: 30px;
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 4px;
  border: 0;
  padding: 0;
  color: var(--ink);
  background: transparent;
  font-weight: 900;
  text-align: left;
  cursor: pointer;
}

.horse-name-button span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.horse-name-button small {
  font-size: 0.67rem;
  font-weight: 800;
  color: #76512c;
}

.player-mark {
  display: inline-grid;
  min-width: 22px;
  height: 22px;
  place-items: center;
  font-size: 1rem;
}

.info-panel {
  min-height: 260px;
  padding: 0;
  overflow: hidden;
}

.tab-list {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-bottom: 3px solid var(--ink);
}

.tab-button {
  min-height: 48px;
  border: 0;
  border-right: 2px solid var(--ink);
  border-radius: 0;
  background: #ededed;
  box-shadow: none;
  font-size: 0.9rem;
}

.tab-button:last-child {
  border-right: 0;
}

.tab-button.active {
  background: var(--paper);
}

.tab-content {
  padding: 10px;
}

.trend-list {
  display: grid;
  gap: 8px;
}

.trend-list div,
.help-grid div,
.odds-rule-box,
.help-ticket {
  display: grid;
  grid-template-columns: 74px 1fr;
  gap: 8px;
  align-items: start;
}

.trend-list strong,
.help-grid strong,
.odds-rule-box strong {
  color: #245d31;
}

.odds-rule-box {
  margin-top: 10px;
  margin-bottom: 14px;
  padding: 8px;
  border: 2px dashed #bb8845;
  border-radius: 6px;
  background: #fffbe8;
  font-size: 0.86rem;
  font-weight: 800;
}

.odds-rule-list {
  display: grid;
  gap: 4px;
}

.odds-rule-list span {
  display: block;
  line-height: 1.45;
}

.paddock-table {
  min-width: 360px;
  font-size: 0.9rem;
}

.paddock-table th:nth-child(1),
.paddock-table td:nth-child(1) {
  width: 52px;
  text-align: center;
}

.paddock-table th:nth-child(3),
.paddock-table td:nth-child(3),
.paddock-table th:nth-child(4),
.paddock-table td:nth-child(4) {
  width: 74px;
  text-align: center;
  font-size: 1.1rem;
}

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

.tipster-box {
  padding: 8px;
  border: 2px solid var(--line);
  border-radius: 6px;
  background: #fffbe6;
}

.tipster-box p {
  margin-bottom: 0;
  font-size: 0.9rem;
}

.tipster-marks {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 6px;
}

.tipster-marks > span {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 3px 6px;
  border: 2px solid #caa46a;
  border-radius: 6px;
  background: #fff3bf;
  font-size: 0.78rem;
  font-weight: 800;
}

.tipster-pick .horse-number {
  width: 24px;
  height: 24px;
  font-size: 0.82rem;
}

.tipster-mark {
  min-width: 20px;
  text-align: center;
}

.help-grid,
.ticket-help {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
}

.help-grid div {
  grid-template-columns: 1fr;
  padding: 8px;
  border: 2px solid var(--line);
  border-radius: 6px;
  background: #fffbe6;
}

.help-grid span {
  line-height: 1.45;
}

.ticket-chip {
  display: inline-flex;
  justify-content: center;
  padding: 4px 8px;
  border: 2px solid var(--ink);
  border-radius: 6px;
  background: #fbd36d;
  font-weight: 900;
}

.marksheet-panel {
  padding: 8px;
}

.purchase-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.icon-button {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  background: #f4f4f4;
  font-size: 1.25rem;
}

.marksheet {
  display: grid;
  gap: 8px;
}

.mark-row {
  display: grid;
  grid-template-columns: 54px 1fr;
  gap: 6px;
  align-items: center;
}

.mark-row.split-row {
  padding-top: 10px;
  border-top: 2px dashed #bb8845;
}

.mark-label {
  display: grid;
  min-height: 40px;
  place-items: center;
  border: 2px solid #75a65c;
  background: #9ad77b;
  font-weight: 950;
}

.mark-options {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.sheet-choice,
.number-choice {
  min-height: 34px;
  padding: 4px 8px;
  background: #fff8d8;
  box-shadow: 0 2px 0 var(--shadow);
  font-size: 0.95rem;
}

.sheet-choice.selected,
.number-choice.selected {
  background: #d7d7d7;
  box-shadow: inset 0 0 0 2px #fff, 0 2px 0 var(--shadow);
}

.sheet-choice:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.number-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(38px, 1fr));
  gap: 7px;
}

.number-choice {
  min-width: 0;
  padding: 4px 0;
  display: grid;
  place-items: center;
  gap: 0;
  font-size: 1.1rem;
}

.number-choice-mark {
  display: block;
  min-height: 13px;
  font-size: 0.68rem;
  line-height: 1;
}

.unit-options {
  flex-wrap: nowrap;
  overflow-x: auto;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
}

.unit-options .sheet-choice {
  flex: 0 0 auto;
  min-width: 58px;
}

.unit-options .max-unit-button {
  min-width: 72px;
  background: #fbd36d;
}

.ticket-description {
  margin: 2px 0 0;
  padding: 8px;
  border: 2px dashed #bb8845;
  border-radius: 6px;
  background: #fffbe8;
  font-size: 0.86rem;
  font-weight: 800;
}

.my-marks-panel {
  margin-top: 8px;
  padding: 8px;
  border: 2px dashed #bb8845;
  border-radius: 6px;
  background: #fffbe8;
  font-size: 0.82rem;
}

.my-marks-panel strong {
  display: block;
  margin-bottom: 5px;
}

.muted-panel {
  color: #6b5a46;
  font-weight: 800;
}

.my-mark-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.my-mark-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 6px;
  border: 2px solid #d2a668;
  border-radius: 6px;
  background: #fff4c4;
  font-weight: 900;
}

.my-mark-item .horse-number {
  width: 22px;
  height: 22px;
  font-size: 0.78rem;
}

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

.purchase-summary div,
.result-money-grid div,
.final-score div {
  display: grid;
  gap: 2px;
  padding: 8px;
  border: 2px solid var(--line);
  border-radius: 6px;
  background: #fffbe6;
}

.purchase-summary span,
.result-money-grid span,
.final-score span {
  font-size: 0.78rem;
  font-weight: 800;
  color: #6b4928;
}

.purchase-summary strong,
.result-money-grid strong,
.final-score strong {
  font-size: 1.05rem;
  font-weight: 950;
}

.error-message,
.notice-message,
.toast {
  grid-column: 1 / -1;
  margin: 0;
  padding: 8px;
  border-radius: 6px;
  font-weight: 900;
}

.error-message,
.toast {
  border: 2px solid var(--danger);
  background: #ffe8e3;
  color: var(--danger);
}

.notice-message {
  border: 2px solid var(--good);
  background: #e6ffd9;
  color: var(--good);
}

.cart-empty,
.cart-list {
  grid-column: 1 / -1;
}

.cart-empty {
  margin: 0;
  padding: 8px;
  border: 2px dashed #bb8845;
  border-radius: 6px;
  background: #fffbe8;
  font-size: 0.82rem;
  font-weight: 900;
}

.cart-list {
  display: grid;
  gap: 6px;
}

.cart-list > strong {
  color: #245d31;
}

.confirm-total {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin: 12px 0;
  padding: 10px;
  border: 3px solid var(--ink);
  border-radius: 8px;
  background: #fffbe6;
}

.ticket-list {
  display: grid;
  gap: 8px;
  margin: 10px 0;
}

.ticket-row {
  position: relative;
  display: grid;
  gap: 8px;
  padding: 9px;
  border: 2px solid var(--line);
  border-radius: 6px;
  background: #fffbe6;
  font-size: 0.88rem;
}

.ticket-row.removable-ticket {
  padding-right: 48px;
}

.ticket-row span {
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 900;
}

.ticket-slip-head {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
}

.ticket-kind {
  padding: 3px 6px;
  border: 2px solid var(--ink);
  border-radius: 6px;
  background: #fbd36d;
  text-align: center;
  white-space: nowrap;
}

.ticket-bet-layout {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 8px;
  align-items: stretch;
}

.ticket-kind-side {
  display: grid;
  place-items: center;
  padding: 4px;
  line-height: 1.15;
  writing-mode: vertical-rl;
  text-orientation: upright;
}

.ticket-bet-main {
  display: grid;
  min-width: 0;
  gap: 5px;
}

.ticket-slip-head-compact {
  display: flex;
  min-width: 0;
  justify-content: flex-end;
}

.ticket-slip-head-compact .ticket-result-label {
  margin-right: auto;
}

.ticket-horse-stack {
  display: grid;
  gap: 5px;
}

.ticket-horse-ref {
  display: inline-flex;
  min-width: 0;
  align-items: center;
  gap: 4px;
}

.ticket-horse-ref.number-only {
  justify-self: start;
}

.ticket-horse-ref.number-only .horse-number {
  width: 28px;
  height: 28px;
  font-size: 0.9rem;
}

.ticket-number-flow {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: max-content;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 4px 2px;
}

.ticket-flow-cell {
  display: grid;
  place-items: center;
}

.ticket-flow-cell .horse-number {
  width: 34px;
  height: 34px;
  font-size: 1rem;
}

.ticket-flow-arrow {
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 950;
}

.ticket-number {
  width: 23px;
  height: 23px;
  font-size: 0.78rem;
  flex: 0 0 auto;
}

.ticket-player-mark {
  min-width: 18px;
  text-align: center;
}

.ticket-result-label {
  justify-self: start;
}

.ticket-slip-foot {
  display: grid;
  gap: 3px;
  justify-items: end;
  text-align: right;
}

.ticket-stake {
  max-width: 100%;
  font-weight: 950;
  overflow-wrap: anywhere;
}

.ticket-money {
  font-weight: 950;
  overflow-wrap: anywhere;
}

.ticket-money {
  font-size: 1rem;
}

.remove-ticket-button {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 34px;
  height: 34px;
  border: 3px solid var(--ink);
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 2px 0 var(--shadow);
  font-weight: 950;
  cursor: pointer;
}

.hit-ticket {
  background: #e4ffd8;
  border-color: var(--good);
}

.record-panel {
  margin: auto 0;
}

.record-best,
.record-run-row {
  display: grid;
  gap: 3px;
  padding: 10px;
  border: 2px solid var(--line);
  border-radius: 6px;
  background: #fffbe6;
}

.record-best {
  margin-bottom: 10px;
  border-width: 3px;
}

.record-best span,
.record-run-row span,
.record-run-row small {
  color: #477046;
  font-weight: 900;
}

.record-best strong {
  font-size: 1.4rem;
}

.record-run-list {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.cutscene {
  min-height: calc(100dvh - 36px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
}

.cutscene-stage {
  position: relative;
  width: min(100%, 430px);
  aspect-ratio: 16 / 10;
  min-height: 238px;
  overflow: hidden;
  border: 4px solid var(--ink);
  border-radius: 8px;
  background: #6fd4ef;
  box-shadow: 0 5px 0 var(--shadow);
}

.movie-stage {
  aspect-ratio: 16 / 9;
  min-height: 0;
  background: #050505;
}

.goal-movie {
  display: block;
  width: 100%;
  height: 100%;
  background: #050505;
  object-fit: contain;
}

.cutscene-sky,
.cutscene-stand,
.race-track,
.goal-post,
.finish-stripe,
.track-dust,
.pixel-horse,
.foreground-crowd {
  position: absolute;
}

.cutscene-sky {
  inset: 0;
  background:
    linear-gradient(transparent 0 58%, rgba(255, 255, 255, 0.28) 58% 60%, transparent 60%),
    linear-gradient(#62cff0 0 62%, #8be66f 62% 100%);
}

.cutscene-sky::before,
.cutscene-sky::after {
  content: "";
  position: absolute;
  height: 16px;
  background: #dff9ff;
  box-shadow:
    18px 0 0 #dff9ff,
    34px 8px 0 #dff9ff,
    -14px 8px 0 #dff9ff;
}

.cutscene-sky::before {
  top: 24px;
  left: 28px;
  width: 42px;
}

.cutscene-sky::after {
  top: 38px;
  right: 110px;
  width: 34px;
  opacity: 0.75;
}

.cutscene-stand {
  top: 18px;
  left: 14px;
  right: 102px;
  height: 74px;
  z-index: 1;
  border: 3px solid var(--ink);
  background: #fff4bb;
  box-shadow: 0 4px 0 rgba(24, 19, 14, 0.36);
}

.stand-roof {
  position: absolute;
  top: -12px;
  left: -6px;
  right: -6px;
  height: 16px;
  border: 3px solid var(--ink);
  background: repeating-linear-gradient(90deg, #e94f3c 0 18px, #ffe07b 18px 36px);
}

.stand-crowd {
  display: grid;
  grid-template-columns: repeat(18, 1fr);
  gap: 3px;
  height: 100%;
  padding: 18px 8px 8px;
}

.stand-dot {
  display: block;
  min-width: 0;
  height: 10px;
  border: 2px solid #2c2218;
  background: #f0d7a7;
}

.dot-1 { background: #f3d06b; }
.dot-2 { background: #5ec2e7; }
.dot-3 { background: #ec7a60; }
.dot-4 { background: #72cb73; }
.dot-5 { background: #f5f1df; }
.dot-6 { background: #b48df0; }

.race-track {
  left: -6px;
  right: -6px;
  bottom: 34px;
  height: 136px;
  z-index: 2;
  border-top: 4px solid #326d3c;
  background:
    linear-gradient(160deg, rgba(255, 255, 255, 0.34) 0 8%, transparent 8% 100%),
    repeating-linear-gradient(0deg, transparent 0 31px, rgba(255, 255, 255, 0.72) 31px 35px),
    linear-gradient(#7bd15e 0 20%, #c6844a 20% 100%);
}

.track-lane {
  position: absolute;
  left: 0;
  right: 0;
  height: 4px;
  background: rgba(255, 246, 204, 0.8);
}

.lane-top { top: 46px; }
.lane-mid { top: 76px; }
.lane-bottom { top: 106px; }

.goal-post {
  top: 18px;
  right: 38px;
  bottom: 38px;
  width: 58px;
  z-index: 5;
}

.goal-board {
  position: absolute;
  top: 0;
  right: 8px;
  padding: 4px 7px;
  border: 3px solid var(--ink);
  background: #fff6cc;
  box-shadow: 0 3px 0 var(--shadow);
  font-size: 0.78rem;
  font-weight: 950;
}

.goal-checker {
  position: absolute;
  top: 33px;
  right: 18px;
  width: 28px;
  bottom: 0;
  border: 3px solid var(--ink);
  background:
    repeating-conic-gradient(#18130e 0 25%, #fff6cc 0 50%) 0 0 / 14px 14px;
}

.finish-stripe {
  right: 86px;
  bottom: 38px;
  width: 20px;
  height: 118px;
  z-index: 3;
  border: 3px solid var(--ink);
  background:
    repeating-linear-gradient(0deg, #fff6cc 0 12px, #18130e 12px 24px);
  opacity: 0.92;
}

.track-dust {
  z-index: 4;
  width: 14px;
  height: 10px;
  background: #e7b36a;
  box-shadow:
    18px 4px 0 #e7b36a,
    34px 1px 0 #e7b36a;
  opacity: 0;
  animation: dust-puff 1.4s ease-out forwards;
}

.dust-one {
  left: 25%;
  bottom: 74px;
}

.dust-two {
  left: 48%;
  bottom: 66px;
  animation-delay: 0.35s;
}

.pixel-horse {
  left: -150px;
  bottom: 48px;
  z-index: 6;
  width: 142px;
  height: 108px;
  animation: horse-finish 1.55s cubic-bezier(0.16, 0.84, 0.24, 1) forwards;
}

.horse-sprite,
.horse-sprite span {
  position: absolute;
  display: block;
}

.horse-sprite {
  inset: 0;
  animation: horse-bob 0.22s steps(2, end) infinite;
}

.horse-body,
.horse-neck,
.horse-head,
.horse-snout,
.horse-tail,
.horse-leg,
.horse-ear {
  border: 4px solid #34140f;
  background: #b7632c;
}

.horse-body {
  left: 34px;
  bottom: 32px;
  width: 68px;
  height: 36px;
  box-shadow: inset 10px 0 0 #d27a35, inset -8px -6px 0 #7c371e;
}

.horse-neck {
  left: 84px;
  bottom: 55px;
  width: 22px;
  height: 34px;
  transform: skewX(-12deg);
  background: #a84f27;
}

.horse-head {
  left: 99px;
  bottom: 70px;
  width: 34px;
  height: 28px;
  background: #c96d31;
  box-shadow: inset 9px 0 0 #df8a42;
}

.horse-snout {
  left: 118px;
  bottom: 63px;
  width: 24px;
  height: 18px;
  background: #d48242;
}

.horse-ear {
  bottom: 93px;
  width: 12px;
  height: 18px;
  background: #9b4426;
}

.ear-one {
  left: 101px;
}

.ear-two {
  left: 116px;
  height: 15px;
}

.horse-tail {
  left: 6px;
  bottom: 56px;
  width: 36px;
  height: 16px;
  background: #5a2416;
  transform: rotate(-16deg);
  transform-origin: right center;
  animation: tail-swing 0.28s steps(2, end) infinite;
}

.horse-mane {
  left: 82px;
  bottom: 66px;
  width: 12px;
  height: 34px;
  background:
    linear-gradient(#4e1f15 0 8px, transparent 8px 12px, #4e1f15 12px 20px, transparent 20px 24px, #4e1f15 24px 34px);
}

.horse-eye {
  left: 124px;
  bottom: 82px;
  width: 5px;
  height: 5px;
  background: #101010;
  box-shadow: 2px 0 0 #fff;
}

.horse-saddle {
  left: 54px;
  bottom: 58px;
  width: 35px;
  height: 18px;
  border: 4px solid #26824a;
  background:
    linear-gradient(90deg, #f4c94d 0 8px, #2fa85c 8px 100%);
}

.horse-leg {
  bottom: 5px;
  width: 13px;
  height: 35px;
  background: #7c371e;
  transform-origin: top center;
}

.horse-leg::after {
  content: "";
  position: absolute;
  left: -4px;
  bottom: -8px;
  width: 18px;
  height: 8px;
  border: 3px solid #34140f;
  background: #2b1710;
}

.leg-front-one {
  left: 91px;
  animation: gallop-front 0.22s steps(2, end) infinite;
}

.leg-front-two {
  left: 76px;
  height: 30px;
  background: #9a4a22;
  animation: gallop-back 0.22s steps(2, end) infinite;
}

.leg-back-one {
  left: 45px;
  animation: gallop-back 0.22s steps(2, end) infinite;
}

.leg-back-two {
  left: 30px;
  height: 31px;
  background: #9a4a22;
  animation: gallop-front 0.22s steps(2, end) infinite;
}

.foreground-crowd {
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 8;
  height: 54px;
  display: flex;
  align-items: flex-end;
  justify-content: space-around;
  padding: 0 8px 8px;
  background:
    linear-gradient(transparent 0 20px, rgba(55, 130, 73, 0.88) 20px 100%);
}

.foreground-crowd::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 18px;
  height: 7px;
  border-block: 2px solid var(--ink);
  background: #fff6cc;
}

.spectator {
  position: relative;
  width: 18px;
  height: 34px;
  border: 3px solid var(--ink);
  background: #f35f4a;
  box-shadow: 0 3px 0 rgba(24, 19, 14, 0.32);
}

.spectator::before {
  content: "";
  position: absolute;
  left: 2px;
  top: -15px;
  width: 12px;
  height: 12px;
  border: 3px solid var(--ink);
  background: #ffd39b;
}

.spectator::after {
  content: "";
  position: absolute;
  left: -5px;
  top: 8px;
  width: 24px;
  height: 6px;
  background: var(--ink);
  transform: rotate(-12deg);
}

.spectator-2,
.spectator-7,
.spectator-11 { background: #5ec2e7; }
.spectator-3,
.spectator-8 { background: #f4cf52; }
.spectator-4,
.spectator-9 { background: #80d873; }
.spectator-5,
.spectator-12 { background: #b48df0; }
.spectator-6,
.spectator-10 { background: #fff6cc; }

@keyframes horse-finish {
  0% {
    left: -150px;
  }
  72% {
    left: calc(100% - 186px);
  }
  100% {
    left: calc(100% - 160px);
  }
}

@keyframes horse-bob {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-4px);
  }
}

@keyframes gallop-front {
  0%, 100% {
    transform: rotate(18deg);
  }
  50% {
    transform: rotate(-24deg);
  }
}

@keyframes gallop-back {
  0%, 100% {
    transform: rotate(-20deg);
  }
  50% {
    transform: rotate(22deg);
  }
}

@keyframes tail-swing {
  0%, 100% {
    transform: rotate(-22deg);
  }
  50% {
    transform: rotate(7deg);
  }
}

@keyframes dust-puff {
  0%, 18% {
    opacity: 0;
    transform: translateX(-16px) scale(0.6);
  }
  38% {
    opacity: 0.85;
  }
  100% {
    opacity: 0;
    transform: translateX(70px) scale(1.35);
  }
}

.result-panel h2 {
  text-align: center;
}

.result-list {
  display: grid;
  gap: 6px;
  margin: 0 0 12px;
  padding: 0;
  list-style: none;
}

.result-list li {
  display: grid;
  grid-template-columns: 44px 36px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border: 2px solid var(--line);
  border-radius: 6px;
  background: #fffbe6;
}

.result-list li:first-child {
  background: #fff1a8;
  border-color: #b48225;
}

.result-list span,
.result-list em {
  font-size: 0.8rem;
  font-style: normal;
  font-weight: 800;
}

.result-list .horse-number {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border: 2px solid var(--ink);
  border-radius: 6px;
}

.result-list strong {
  min-width: 0;
  overflow-wrap: anywhere;
}

.result-money-grid,
.final-score {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.details-toggle {
  width: 100%;
  min-height: 44px;
  margin-bottom: 6px;
  background: #f5f5f5;
}

.final-panel h1 {
  font-size: 2rem;
}

.result-graph {
  display: grid;
  gap: 8px;
  margin: 12px 0 14px;
  padding: 10px;
  border: 3px solid var(--ink);
  border-radius: 8px;
  background: #fffbe6;
}

.graph-heading {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: end;
}

.graph-heading strong {
  font-size: 1.05rem;
}

.graph-heading span {
  color: #6b4928;
  font-size: 0.78rem;
  font-weight: 900;
  text-align: right;
}

.balance-chart-svg {
  display: block;
  width: 100%;
  height: auto;
}

.chart-bg {
  fill: #fffbe6;
}

.chart-title,
.chart-y-label,
.chart-x-label,
.chart-end-label {
  fill: var(--ink);
  font-family: inherit;
  font-weight: 900;
}

.chart-title {
  font-size: 18px;
}

.chart-y-label,
.chart-x-label,
.chart-end-label {
  font-size: 14px;
}

.chart-y-label {
  text-anchor: end;
}

.chart-x-label {
  text-anchor: middle;
}

.chart-grid {
  stroke: #d8bd7c;
  stroke-width: 2;
  stroke-dasharray: 6 6;
}

.chart-tick,
.chart-axis {
  stroke: var(--ink);
  stroke-width: 3;
}

.chart-line {
  fill: none;
  stroke: #f47f20;
  stroke-width: 6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-end-dot {
  fill: #f47f20;
  stroke: var(--ink);
  stroke-width: 3;
}

.chart-high-dot {
  fill: #42bd61;
  stroke: var(--ink);
  stroke-width: 3;
}

.share-text {
  width: 100%;
  min-height: 170px;
  padding: 10px;
  border: 3px solid var(--ink);
  border-radius: 8px;
  background: #fffbe6;
  resize: vertical;
  font-size: 0.88rem;
}

.history-details {
  margin-top: 12px;
}

.history-details + .action-row {
  margin-top: 18px;
}

.history-details summary {
  min-height: 44px;
  padding: 10px;
  border: 3px solid var(--ink);
  border-radius: 8px;
  background: #f4f4f4;
  font-weight: 900;
  cursor: pointer;
}

.history-list {
  display: grid;
  gap: 6px;
  margin-top: 8px;
}

.history-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 8px;
  padding: 8px;
  border: 2px solid var(--line);
  border-radius: 6px;
  background: #fffbe6;
}

.history-row span {
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 900;
}

.history-row small {
  grid-column: 1 / -1;
  color: #6b4928;
  font-weight: 800;
}

.save-note {
  margin-bottom: 12px;
  font-weight: 900;
  color: #477046;
}

.empty-state {
  margin: 10px 0;
  padding: 10px;
  border: 2px dashed var(--line);
  border-radius: 6px;
  background: #fffbe6;
  text-align: center;
  font-weight: 900;
}

code {
  padding: 2px 5px;
  border: 1px solid #d5b26d;
  border-radius: 4px;
  background: #fffbe6;
}

@media (max-width: 380px) {
  .game-shell {
    padding-inline: 8px;
  }

  h1 {
    font-size: 2.1rem;
  }

  .race-banner {
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas:
      "count title title"
      "meta meta money";
  }

  .race-title {
    font-size: clamp(0.78rem, calc(1.84rem - var(--race-title-length, 8) * 0.075rem), 1.38rem);
  }

  .bottom-actions,
  .action-row {
    gap: 8px;
  }

  .pixel-button {
    min-height: 50px;
    padding-inline: 12px;
    font-size: 1rem;
  }

  .purchase-summary,
  .result-money-grid,
  .final-score {
    grid-template-columns: 1fr;
  }

  .graph-heading {
    grid-template-columns: 1fr;
  }

  .graph-heading span {
    text-align: left;
  }

  .ticket-slip-head {
    grid-template-columns: auto 1fr auto;
  }
}
