:root {
  color-scheme: dark;
  --ink: #e8eef2;
  --muted: #aebbc5;
  --night: #081827;
  --felt: #102b3f;
  --felt-deep: #0b2233;
  --paper: #f4e8cf;
  --paper-ink: #211b17;
  --brass: #d79a45;
  --brass-dark: #8f6129;
  --red: #a93645;
  --red-bright: #c64a57;
  --line: rgba(215, 154, 69, 0.55);
  --shadow: 0 8px 0 rgba(0, 0, 0, 0.2);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Noto Sans JP", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--night);
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background: var(--night);
}

button,
select {
  font: inherit;
}

button,
a,
select {
  -webkit-tap-highlight-color: transparent;
}

button {
  color: inherit;
}

button:focus-visible,
a:focus-visible,
select:focus-visible {
  outline: 3px solid #f7c976;
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 0.5rem;
  left: 0.5rem;
  padding: 0.75rem 1rem;
  color: var(--paper-ink);
  background: var(--paper);
  transform: translateY(-150%);
}

.skip-link:focus {
  transform: translateY(0);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.8rem clamp(0.75rem, 3vw, 1.5rem);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--paper);
  text-decoration: none;
  white-space: nowrap;
}

.brand strong {
  font-family: ui-serif, "Yu Mincho", "Hiragino Mincho ProN", serif;
  font-size: clamp(1.05rem, 3vw, 1.45rem);
  letter-spacing: 0.06em;
}

.topbar nav {
  display: flex;
  gap: 0.4rem;
  overflow-x: auto;
}

.topbar button {
  min-height: 40px;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--brass-dark);
  border-radius: 5px;
  color: var(--ink);
  background: transparent;
  cursor: pointer;
  white-space: nowrap;
  font-size: 0.82rem;
  font-weight: 700;
}

.topbar button:hover {
  border-color: var(--brass);
  background: var(--felt);
}

.page-layout {
  display: grid;
  width: min(100%, 1220px);
  margin: 0 auto;
  padding: clamp(0.6rem, 2.5vw, 1.25rem);
}

.game-shell {
  min-width: 0;
  padding: clamp(0.55rem, 2vw, 1rem);
  border: 1px solid var(--line);
  background: var(--felt-deep);
  box-shadow: var(--shadow);
}

.opponents {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(0.35rem, 1.5vw, 0.8rem);
}

.npc {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--brass-dark);
  border-radius: 7px;
  color: #202c34;
  background: #dce3df;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.16);
  transition: border-color 160ms ease, transform 160ms ease;
}

.npc.is-current {
  border-color: #f1bd69;
  box-shadow: inset 0 0 0 2px rgba(241, 189, 105, 0.2);
  transform: translateY(-2px);
}

.npc.is-burst {
  border-color: var(--red-bright);
  color: var(--ink);
  background: #17131b;
  box-shadow: inset 0 0 0 2px rgba(198, 74, 87, 0.2);
}

.npc-portrait {
  position: relative;
  aspect-ratio: 1.16;
  width: 100%;
  border-bottom: 1px solid var(--brass-dark);
  background-color: #8da3a6;
  background-image: url("./assets/owl-cast.webp");
  background-blend-mode: screen;
  background-repeat: no-repeat;
  background-size: 300% auto;
  filter: contrast(1.15) saturate(1.1);
}

.npc.is-burst .npc-portrait {
  filter: grayscale(0.7) brightness(0.5);
}

.npc-burst-badge {
  position: absolute;
  top: 50%;
  left: 50%;
  padding: 0.2rem 0.4rem;
  border: 2px solid #ff9ba5;
  color: #ffd7db;
  background: rgba(76, 12, 22, 0.82);
  font-family: ui-serif, Georgia, serif;
  font-size: clamp(0.62rem, 2.4vw, 0.9rem);
  font-weight: 900;
  letter-spacing: 0.08em;
  transform: translate(-50%, -50%) rotate(-8deg);
}

.portrait-left {
  background-position: left center;
}

.portrait-center {
  background-position: center center;
}

.portrait-right {
  background-position: right center;
}

.npc > div:last-child {
  display: grid;
  gap: 0.15rem;
  padding: 0.45rem;
}

.npc strong {
  overflow: hidden;
  font-family: ui-serif, "Yu Mincho", "Hiragino Mincho ProN", serif;
  font-size: clamp(0.84rem, 2.6vw, 1rem);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.npc > div:last-child span {
  overflow: hidden;
  color: #50616a;
  font-size: clamp(0.65rem, 2vw, 0.78rem);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.npc.is-burst > div:last-child span {
  color: #d9bdc1;
}

.speech {
  position: relative;
  display: grid;
  gap: 0.25rem;
  width: min(92%, 660px);
  min-height: 76px;
  margin: 0.85rem auto;
  padding: 0.8rem 1rem;
  border: 2px solid var(--brass-dark);
  border-radius: 8px;
  color: var(--paper-ink);
  background: var(--paper);
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.22);
}

.speech::before {
  position: absolute;
  top: -10px;
  left: 50%;
  width: 16px;
  height: 16px;
  border-top: 2px solid var(--brass-dark);
  border-left: 2px solid var(--brass-dark);
  background: var(--paper);
  content: "";
  transform: translateX(-50%) rotate(45deg);
}

.speech strong {
  color: #714820;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
}

.speech p {
  margin: 0;
  font-family: ui-serif, "Yu Mincho", "Hiragino Mincho ProN", serif;
  font-size: clamp(0.92rem, 2.7vw, 1.05rem);
  font-weight: 700;
  line-height: 1.55;
}

.board-panel,
.hand-panel {
  border: 1px solid var(--line);
  background: var(--felt);
}

.panel-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.55rem 0.7rem;
  border-bottom: 1px solid var(--line);
}

.panel-heading h1,
.panel-heading h2 {
  margin: 0;
  font-family: ui-serif, "Yu Mincho", "Hiragino Mincho ProN", serif;
  font-size: 1rem;
}

.panel-heading p {
  margin: 0;
  color: var(--muted);
  font-size: 0.72rem;
  text-align: right;
}

.board {
  display: grid;
  gap: 0.28rem;
  padding: 0.55rem 0.35rem 0.65rem;
  overflow: hidden;
}

.board-row {
  display: grid;
  grid-template-columns: minmax(24px, 0.9fr) repeat(13, minmax(18px, 1fr));
  gap: clamp(1px, 0.35vw, 4px);
  min-width: 0;
}

.board-heading {
  align-items: end;
}

.suit-heading,
.rank-label,
.board-card {
  display: grid;
  min-width: 0;
  place-items: center;
}

.suit-heading {
  font-size: clamp(1rem, 4vw, 1.35rem);
}

.rank-label {
  min-height: 18px;
  color: var(--muted);
  font-family: ui-serif, Georgia, serif;
  font-size: clamp(0.58rem, 2.2vw, 0.78rem);
}

.rank-seven {
  color: #f5c979;
  font-weight: 900;
}

.board-card {
  aspect-ratio: 0.73;
  max-height: 54px;
  border: 1px dashed rgba(215, 154, 69, 0.4);
  border-radius: 3px;
  color: transparent;
}

.board-card-rank,
.board-card-suit {
  font-family: ui-serif, Georgia, serif;
  font-size: clamp(0.52rem, 2vw, 0.82rem);
  font-weight: 900;
  line-height: 0.85;
}

.board-card.is-visible {
  border-style: solid;
  border-color: #d3c5a9;
  color: var(--paper-ink);
  background: var(--paper);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.2);
}

.board-card.is-burst-revealed {
  border-color: #8c806d;
  background:
    repeating-linear-gradient(
      135deg,
      rgba(8, 24, 39, 0.12) 0,
      rgba(8, 24, 39, 0.12) 2px,
      transparent 2px,
      transparent 6px
    ),
    #cfc2a7;
  box-shadow: inset 0 0 0 1px rgba(8, 24, 39, 0.18), 0 2px 0 rgba(0, 0, 0, 0.28);
}

.board-card.suit-red.is-visible,
.suit-red {
  color: var(--red);
}

.board-card.is-frontier:not(.is-visible) {
  border-color: #dfb45e;
  background: rgba(215, 154, 69, 0.08);
}

.board-card.is-seven {
  border-color: var(--brass);
  box-shadow: inset 0 0 0 1px var(--brass), 0 2px 0 rgba(0, 0, 0, 0.2);
}

.turn-banner {
  width: fit-content;
  margin: 0.8rem auto;
  padding: 0.45rem 1.6rem;
  border-top: 1px solid var(--brass);
  border-bottom: 1px solid var(--brass);
  color: #f4c879;
  font-family: ui-serif, "Yu Mincho", "Hiragino Mincho ProN", serif;
  font-size: clamp(1rem, 4vw, 1.35rem);
  font-weight: 800;
  letter-spacing: 0.08em;
  text-align: center;
}

.hand {
  display: flex;
  gap: 0.35rem;
  min-height: 96px;
  padding: 0.65rem;
  overflow-x: auto;
  scroll-padding-inline: 0.65rem;
  scrollbar-color: var(--brass-dark) var(--night);
}

.hand-card {
  position: relative;
  display: grid;
  flex: 0 0 clamp(48px, 14vw, 62px);
  aspect-ratio: 0.7;
  padding: 0.3rem;
  border: 1px solid #c6b99e;
  border-radius: 5px;
  color: var(--paper-ink);
  background: var(--paper);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.28);
  cursor: pointer;
  place-items: center;
  transition: transform 140ms ease, border-color 140ms ease;
}

.hand-card strong {
  font-family: ui-serif, Georgia, serif;
  font-size: 1.25rem;
}

.hand-card span {
  font-size: 1.2rem;
}

.hand-card.suit-red {
  color: var(--red);
}

.hand-card.is-locked {
  cursor: not-allowed;
  filter: saturate(0.45) brightness(0.72);
  opacity: 0.64;
}

.hand-card.is-legal:not(:disabled):hover {
  transform: translateY(-4px);
}

.hand-card.is-selected {
  border-color: #ffd27d;
  box-shadow: 0 0 0 3px var(--brass), 0 7px 0 rgba(0, 0, 0, 0.28);
  transform: translateY(-5px);
}

.empty-hand {
  margin: auto;
  color: var(--muted);
}

.hand-panel.is-burst {
  border-color: var(--red-bright);
  background: #17131b;
  box-shadow: inset 0 0 0 2px rgba(198, 74, 87, 0.16);
}

.hand-panel.is-burst .empty-hand {
  color: #ffd7db;
}

.actions {
  position: sticky;
  z-index: 5;
  bottom: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
  padding: 0.8rem 0 max(0.8rem, env(safe-area-inset-bottom));
  background: var(--felt-deep);
}

.actions button,
.result button {
  min-height: 54px;
  border: 2px solid var(--brass);
  border-radius: 6px;
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.25);
  cursor: pointer;
  font-family: ui-serif, "Yu Mincho", "Hiragino Mincho ProN", serif;
  font-size: clamp(1rem, 4vw, 1.3rem);
  font-weight: 900;
}

.action-play {
  background: var(--red);
}

.action-pass {
  background: #173a62;
}

.actions button:disabled {
  cursor: not-allowed;
  filter: grayscale(0.75);
  opacity: 0.48;
}

.result {
  padding: 1rem;
  border: 1px solid var(--brass);
  background: var(--night);
  text-align: center;
}

.result h2 {
  margin-top: 0;
  font-family: ui-serif, "Yu Mincho", "Hiragino Mincho ProN", serif;
}

.result ol {
  display: grid;
  gap: 0.35rem;
  width: min(100%, 360px);
  margin: 1rem auto;
  padding: 0;
  list-style: none;
}

.result li {
  display: flex;
  justify-content: space-between;
  padding: 0.55rem 0.8rem;
  border-bottom: 1px solid var(--line);
}

.result li.is-burst {
  border-left: 4px solid var(--red-bright);
  color: #e4b9bd;
  background: rgba(169, 54, 69, 0.12);
}

.result button {
  padding-inline: 2rem;
  color: var(--paper-ink);
  background: var(--paper);
}

.ad-region {
  min-width: 0;
  min-height: 280px;
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(174, 187, 197, 0.25);
}

.ad-region > p {
  margin: 0 0 0.65rem;
  color: var(--muted);
  font-size: 0.7rem;
  text-align: center;
}

footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem 1rem;
  padding: 1.5rem 1rem 2rem;
  color: var(--muted);
  font-size: 0.78rem;
}

footer a {
  color: var(--paper);
}

dialog {
  width: min(calc(100% - 2rem), 520px);
  max-height: min(720px, calc(100vh - 2rem));
  padding: 1rem;
  border: 1px solid var(--brass);
  border-radius: 7px;
  color: var(--ink);
  background: var(--felt-deep);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.55);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.72);
}

.dialog-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--line);
}

.dialog-heading h2 {
  margin: 0;
}

.dialog-heading button,
dialog select,
.danger-button {
  min-height: 42px;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--brass-dark);
  border-radius: 4px;
  color: var(--ink);
  background: var(--night);
}

dialog label {
  display: grid;
  grid-template-columns: 1fr minmax(140px, 0.7fr);
  align-items: center;
  gap: 1rem;
  margin-block: 0.8rem;
}

dialog p {
  color: var(--muted);
  line-height: 1.7;
}

.danger-button {
  border-color: var(--red-bright);
  color: #ffdce0;
  cursor: pointer;
}

.history {
  display: grid;
  gap: 0.75rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.history li {
  display: grid;
  grid-template-columns: minmax(4.5rem, auto) 1fr;
  gap: 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid rgba(215, 154, 69, 0.2);
  line-height: 1.6;
}

.history strong {
  color: #f4c879;
}

@media (min-width: 1060px) {
  .page-layout {
    grid-template-columns: minmax(0, 860px) minmax(260px, 320px);
    align-items: start;
    gap: 2rem;
  }

  .ad-region {
    min-height: 600px;
    margin-top: 0;
    padding-top: 0;
    border-top: 0;
    border-left: 1px solid rgba(174, 187, 197, 0.25);
    padding-left: 1.25rem;
  }

  .npc-portrait {
    aspect-ratio: 1.5;
  }

  .board-card {
    max-height: 58px;
  }
}

@media (max-width: 620px) {
  .topbar {
    align-items: flex-start;
    padding-inline: 0.65rem;
  }

  .topbar nav {
    max-width: 60%;
  }

  .topbar button {
    min-height: 38px;
    padding-inline: 0.55rem;
    font-size: 0.75rem;
  }

  .page-layout {
    padding: 0.45rem;
  }

  .game-shell {
    padding: 0.4rem;
  }

  .speech {
    width: calc(100% - 0.7rem);
  }

  .panel-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 0.2rem;
  }

  .panel-heading p {
    text-align: left;
  }
}

@media (max-width: 360px) {
  .brand strong {
    font-size: 0.95rem;
  }

  .topbar nav {
    max-width: 58%;
  }

  .npc > div:last-child {
    padding: 0.32rem;
  }

  .npc > div:last-child span {
    font-size: 0.58rem;
  }

  .board {
    padding-inline: 0.15rem;
  }

  .board-row {
    grid-template-columns: 22px repeat(13, minmax(17px, 1fr));
  }

  .actions {
    gap: 0.4rem;
  }
}

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