:root {
  color-scheme: light;
  --ink: #15171a;
  --muted: #68717b;
  --paper: #fffdf8;
  --paper-deep: #f7f2e8;
  --accent: #e0522f;
  --green: #1f6a58;
  --blue: #25637d;
  --line: #d9dde2;
  --shadow: 0 26px 65px rgba(15, 23, 42, 0.2);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

html {
  height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  background: linear-gradient(135deg, #eef3f1 0%, #e8edf5 52%, #f4ede8 100%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  font: inherit;
}

.game-shell {
  width: 100vw;
  height: 100svh;
  display: grid;
  place-items: center;
  padding: clamp(20px, 4vw, 48px);
  overflow: hidden;
}

.table {
  width: min(1120px, 100%);
  height: min(820px, calc(100svh - 40px));
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 22px;
  padding: clamp(18px, 3vw, 34px);
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.48);
  box-shadow: 0 30px 100px rgba(15, 23, 42, 0.12);
}

body.card-only .game-shell {
  height: 100svh;
  padding: 0;
}

body.card-only .table {
  width: 100%;
  height: 100svh;
  display: grid;
  place-items: center;
  padding: 10px;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

body.card-only .topbar {
  display: none;
}

body.card-only .game-layout,
body.card-only .play-area {
  min-height: calc(100svh - 20px);
}

.topbar {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 18px;
  color: #161b22;
}

.kicker {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 6vw, 5.4rem);
  line-height: 0.92;
  max-width: 760px;
  text-wrap: balance;
}

.start-panel {
  align-self: center;
  justify-self: center;
  width: min(520px, 100%);
  max-height: 100%;
  display: grid;
  gap: 22px;
  padding: clamp(24px, 5vw, 38px);
  border: 1px solid rgba(15, 23, 42, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: 0 24px 65px rgba(15, 23, 42, 0.1);
}

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

.role-button {
  width: 100%;
}

.player-join {
  display: grid;
  gap: 12px;
  padding-top: 16px;
  border-top: 1px solid rgba(15, 23, 42, 0.1);
}

.scanner-video {
  width: 100%;
  max-height: min(230px, 30svh);
  aspect-ratio: 4 / 3;
  display: block;
  object-fit: cover;
  border: 1px solid rgba(15, 23, 42, 0.12);
  border-radius: 8px;
  background: #15171a;
}

.scanner-status {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.35;
}

.join-code-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.join-code-row input {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid rgba(15, 23, 42, 0.14);
  border-radius: 8px;
  color: var(--ink);
  background: #ffffff;
  font: inherit;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.start-panel h2,
.invite-content h2,
.wait-content h2,
.name-content h2 {
  font-size: clamp(1.5rem, 4vw, 2.15rem);
  line-height: 1.05;
}

.start-panel p {
  margin-top: 10px;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.5;
}

.game-layout {
  width: 100%;
  display: grid;
  place-items: center;
}

.play-area {
  width: 100%;
  min-height: 100%;
  display: grid;
  grid-template-rows: auto auto auto;
  align-content: center;
  justify-items: center;
  row-gap: 7px;
}

.app-title {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: clamp(30px, 6svh, 46px);
  color: var(--ink);
  font-size: clamp(1.45rem, 5vw, 2.45rem);
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0;
}

.app-title img {
  width: clamp(28px, 7vw, 44px);
  height: clamp(28px, 7vw, 44px);
  object-fit: contain;
  transform: translateY(1px);
}

.dictionary-card {
  width: min(430px, calc((100svh - 104px) * 2 / 3), calc(100vw - 20px));
  aspect-ratio: 2 / 3;
  position: relative;
  display: grid;
  place-items: center;
  padding: clamp(24px, min(5.7vw, 4svh), 42px);
  overflow: hidden;
  border: 1px solid rgba(15, 23, 42, 0.1);
  border-radius: 8px;
  background: linear-gradient(180deg, var(--paper), var(--paper-deep));
  box-shadow: var(--shadow);
  transform-origin: center bottom;
  transition: transform 260ms ease, box-shadow 260ms ease;
}

.dictionary-card.is-interactive {
  cursor: default;
}

.close-button {
  position: absolute;
  z-index: 4;
  top: 20px;
  right: 20px;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  color: #15171a;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.12);
  cursor: pointer;
  font-size: 1.5rem;
  line-height: 1;
}

.close-button:hover {
  background: #ffffff;
}

.dictionary-card.is-drawing {
  transform: translateY(-7px) rotate(1deg);
  box-shadow: 0 34px 85px rgba(33, 28, 20, 0.34);
}

.dictionary-card::before,
.dictionary-card::after {
  content: "";
  position: absolute;
  inset: 16px;
  border: 1px solid rgba(15, 23, 42, 0.12);
  border-radius: 8px;
  pointer-events: none;
}

.dictionary-card::after {
  content: none;
}

.card-corners {
  position: absolute;
  inset: 23px;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
}

.card-corners img {
  width: clamp(28px, 7vw, 42px);
  height: clamp(28px, 7vw, 42px);
  object-fit: contain;
  filter: drop-shadow(0 2px 1px rgba(35, 32, 26, 0.16));
}

.card-corners img:last-child {
  align-self: end;
  transform: rotate(180deg);
}

.entry {
  width: 100%;
  max-height: 100%;
  text-align: left;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  transform: translateY(3px);
}

.entry-overline {
  color: var(--blue);
  font-size: clamp(0.66rem, 2vw, 0.76rem);
  font-weight: 800;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.entry h2 {
  margin-top: 10px;
  font-size: clamp(2rem, 7vw, 3.55rem);
  line-height: 0.96;
  letter-spacing: 0;
  overflow-wrap: anywhere;
  font-weight: 850;
}

.entry-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
  color: var(--muted);
  font-size: clamp(0.78rem, 2.4vw, 0.9rem);
  line-height: 1.45;
}

.entry-meta span + span::before {
  content: "•";
  margin-right: 8px;
  color: var(--accent);
}

.hairline {
  width: 100%;
  height: 1px;
  margin: 18px 0;
  background: var(--line);
}

.entry-definition {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 9px;
  font-size: clamp(1.02rem, 3.45vw, 1.22rem);
  line-height: 1.42;
}

body.master-mode:not(.is-revealed) .entry-definition,
body.master-mode:not(.is-revealed) .entry-note {
  cursor: pointer;
}

body.master-mode:not(.is-revealed) .entry-definition {
  margin: -8px -10px 0;
  padding: 10px;
  border: 1px solid rgba(224, 82, 47, 0.24);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
}

body.master-mode:not(.is-revealed) .entry-note {
  margin: 10px -10px 0;
  padding: 10px;
  border: 1px solid rgba(31, 106, 88, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.68);
}

.definition-number {
  width: 24px;
  height: 24px;
  display: inline-grid;
  place-items: center;
  color: #ffffff;
  background: var(--accent);
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 800;
}

.entry-note {
  margin-top: 18px;
  color: var(--green);
  font-size: clamp(0.8rem, 2.5vw, 0.95rem);
  font-style: normal;
  line-height: 1.45;
}

.player-list {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 14px;
}

.player-chip {
  width: 54px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  padding: 5px;
  overflow: hidden;
  border: 1px solid rgba(15, 23, 42, 0.12);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.74);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.08);
  font-size: 0.68rem;
  font-weight: 850;
  line-height: 1.05;
  text-align: center;
  overflow-wrap: anywhere;
}

.game-id {
  width: min(430px, calc((100svh - 104px) * 2 / 3), calc(100vw - 20px));
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: rgba(21, 23, 26, 0.58);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-align: left;
}

.player-meta-name {
  max-width: 45%;
  overflow: hidden;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.invite-content,
.wait-content,
.name-content {
  width: 100%;
  display: grid;
  justify-items: center;
  gap: clamp(12px, 3svh, 22px);
  text-align: center;
}

.invite-content .entry-overline,
.wait-content .entry-overline,
.name-content .entry-overline {
  justify-self: start;
}

.invite-content h2,
.wait-content h2,
.name-content h2 {
  width: 100%;
}

.invite-content p:last-child,
.wait-content p:last-child,
.name-content p {
  max-width: 280px;
  color: var(--muted);
  font-size: clamp(0.88rem, 2.6vw, 1rem);
  line-height: 1.45;
}

.name-content input {
  width: min(280px, 100%);
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid rgba(15, 23, 42, 0.14);
  border-radius: 8px;
  color: var(--ink);
  background: #ffffff;
  font: inherit;
  font-size: 1.1rem;
  font-weight: 800;
  text-align: center;
}

.wait-content::before {
  content: "";
  width: 54px;
  height: 54px;
  border: 5px solid rgba(224, 82, 47, 0.16);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.next-card-button {
  position: absolute;
  z-index: 3;
  left: 50%;
  bottom: clamp(34px, min(7vw, 5svh), 56px);
  min-height: 46px;
  padding: 0 20px;
  border: 0;
  border-radius: 8px;
  color: #ffffff;
  background: var(--accent);
  box-shadow: 0 12px 28px rgba(224, 82, 47, 0.22);
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 850;
  line-height: 1;
  transform: translateX(-50%);
  white-space: nowrap;
}

.next-card-button:hover {
  box-shadow: 0 16px 32px rgba(15, 23, 42, 0.16);
  transform: translateX(-50%) translateY(-1px);
}

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

.qr-code {
  width: min(240px, 58vw, 34svh);
  aspect-ratio: 1;
  display: block;
  padding: 12px;
  border: 1px solid rgba(15, 23, 42, 0.1);
  border-radius: 8px;
  background: #ffffff;
}

body.player-mode .entry-definition,
body.player-mode .entry-note {
  user-select: none;
}

body.player-mode #entry-definition,
body.player-mode #entry-note {
  filter: blur(7px);
}

body.player-mode.is-revealed #entry-definition,
body.player-mode.is-revealed #entry-note {
  filter: none;
}

body.player-mode .definition-number {
  filter: none;
}

.draw-button {
  cursor: pointer;
  border: 0;
  border-radius: 8px;
  color: #ffffff;
  background: var(--accent);
  box-shadow: 0 12px 28px rgba(224, 82, 47, 0.22);
  transition: transform 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

.draw-button {
  min-height: 56px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 0 26px;
  font-weight: 850;
}

.draw-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 16px 32px rgba(15, 23, 42, 0.16);
}

.draw-button:active {
  transform: translateY(0);
}

.confirm-dialog {
  width: min(420px, calc(100vw - 36px));
  padding: 0;
  border: 1px solid rgba(15, 23, 42, 0.12);
  border-radius: 8px;
  color: var(--ink);
  background: #ffffff;
  box-shadow: 0 28px 80px rgba(15, 23, 42, 0.24);
}

.confirm-dialog::backdrop {
  background: rgba(15, 23, 42, 0.35);
  backdrop-filter: blur(3px);
}

.confirm-dialog form {
  display: grid;
  gap: 14px;
  padding: 22px;
}

.confirm-dialog h2 {
  font-size: 1.45rem;
  line-height: 1.1;
}

.confirm-dialog p {
  color: var(--muted);
  line-height: 1.45;
}

.dialog-actions {
  display: flex;
  justify-content: end;
  gap: 10px;
  margin-top: 8px;
}

.secondary-button,
.danger-button {
  min-height: 42px;
  padding: 0 16px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 750;
}

.secondary-button {
  border: 1px solid rgba(15, 23, 42, 0.14);
  color: #20242b;
  background: #ffffff;
}

.danger-button {
  border: 0;
  color: #ffffff;
  background: var(--accent);
}

@media (max-width: 780px) {
  .game-shell {
    padding: 12px;
  }

  .table {
    height: calc(100svh - 24px);
    gap: 17px;
  }

  .topbar {
    flex-direction: column;
  }

  .dictionary-card {
    width: min(430px, calc((100svh - 110px) * 2 / 3), calc(100vw - 24px));
  }

  .game-id {
    width: min(430px, calc((100svh - 110px) * 2 / 3), calc(100vw - 24px));
  }

  .draw-button {
    flex: 1;
    max-width: 245px;
  }
}
