: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);
}

.start-actions {
  display: grid;
  gap: 10px;
}

.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-header {
  width: min(430px, calc((100svh - 104px) * 2 / 3), calc(100vw - 20px));
  display: grid;
  grid-template-columns: 40px 1fr 40px;
  align-items: center;
}

.app-title {
  grid-column: 2;
  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, 54px);
  height: clamp(28px, 7vw, 54px);
  object-fit: contain;
  transform: translateY(-3px) translateX(4px);
}

.dictionary-card {
  --card-bg-top: var(--paper);
  --card-bg-bottom: var(--paper-deep);
  --card-accent: var(--accent);
  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(--card-bg-top), var(--card-bg-bottom));
  box-shadow: var(--shadow);
  transform-origin: center bottom;
  transition: transform 260ms ease, box-shadow 260ms ease;
}

.dictionary-card[data-card-kind="explain"] {
  --card-bg-top: #fffdf8;
  --card-bg-bottom: #f7f2e8;
  --card-accent: #e0522f;
}

.dictionary-card[data-card-kind="rhyme"] {
  --card-bg-top: #f4fbff;
  --card-bg-bottom: #e4f0f7;
  --card-accent: #25637d;
}

.dictionary-card[data-card-kind="sing"] {
  --card-bg-top: #fff9e9;
  --card-bg-bottom: #f4e7fb;
  --card-accent: #8a4f9e;
}

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

.close-button {
  grid-column: 3;
  justify-self: end;
  z-index: 4;
  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);
}

.type-corners {
  position: absolute;
  inset: 23px;
  pointer-events: none;
}

.type-corners img {
  position: absolute;
  width: clamp(30px, 7vw, 44px);
  aspect-ratio: 1;
  object-fit: contain;
  filter: drop-shadow(0 2px 1px rgba(35, 32, 26, 0.14));
}

.type-corners img:first-child {
  top: 0;
  right: 0;
}

.type-corners img:last-child {
  bottom: 0;
  left: 0;
  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);
}

.card-prompt {
  margin-bottom: 8px;
  color: var(--card-accent);
  font-size: clamp(0.78rem, 2.35vw, 0.92rem);
  font-weight: 850;
  line-height: 1.25;
}

.entry h2 {
  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(--card-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 color-mix(in srgb, var(--card-accent), transparent 74%);
  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(--card-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;
}

.invite-player-list {
  max-width: 260px;
  justify-content: center;
  margin-top: 0;
}

.invite-player-list .player-chip {
  cursor: pointer;
}

.invite-player-list .player-chip:hover {
  border-color: rgba(224, 82, 47, 0.38);
  box-shadow: 0 10px 22px rgba(224, 82, 47, 0.14);
  transform: translateY(-1px);
}

.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 h2,
.wait-content h2,
.name-content h2 {
  width: 100%;
}

.invite-content > p,
.wait-content > p,
.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(--card-accent);
  box-shadow: 0 12px 28px color-mix(in srgb, var(--card-accent), transparent 78%);
  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));
  }

  .app-header {
    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;
  }
}

@media (max-width: 520px), (max-height: 720px) {
  .play-area {
    row-gap: 5px;
  }

  .app-title {
    height: clamp(24px, 5svh, 34px);
    font-size: clamp(1.15rem, 4.6vw, 1.65rem);
  }

  .app-title img {
    width: clamp(24px, 6vw, 38px);
    height: clamp(24px, 6vw, 38px);
  }

  .dictionary-card {
    width: min(390px, calc((100svh - 82px) * 2 / 3), calc(100vw - 18px));
    padding: clamp(20px, min(5vw, 3.2svh), 30px);
  }

  .app-header {
    width: min(390px, calc((100svh - 82px) * 2 / 3), calc(100vw - 18px));
    grid-template-columns: 34px 1fr 34px;
  }

  .close-button {
    width: 30px;
    height: 30px;
    font-size: 1.35rem;
  }

  .card-corners {
    inset: 18px;
  }

  .card-corners img {
    width: clamp(24px, 6vw, 34px);
    height: clamp(24px, 6vw, 34px);
  }

  .entry h2 {
    font-size: clamp(1.55rem, 6vw, 2.35rem);
    line-height: 1;
  }

  .card-prompt {
    margin-bottom: 6px;
    font-size: clamp(0.66rem, 2.45vw, 0.78rem);
  }

  .type-corners {
    inset: 18px;
  }

  .type-corners img {
    width: clamp(24px, 6vw, 34px);
  }

  .entry-meta {
    margin-top: 8px;
    font-size: clamp(0.66rem, 2.2vw, 0.78rem);
    line-height: 1.32;
  }

  .hairline {
    margin: 12px 0;
  }

  .entry-definition {
    grid-template-columns: 23px 1fr;
    gap: 7px;
    font-size: clamp(0.82rem, 3vw, 1rem);
    line-height: 1.32;
  }

  .definition-number {
    width: 20px;
    height: 20px;
    font-size: 0.66rem;
  }

  .entry-note {
    margin-top: 12px;
    font-size: clamp(0.68rem, 2.25vw, 0.82rem);
    line-height: 1.34;
  }

  .player-list {
    gap: 6px;
    margin-top: 10px;
  }

  .player-chip {
    width: 42px;
    padding: 4px;
    border-radius: 7px;
    font-size: 0.56rem;
  }

  .game-id {
    width: min(390px, calc((100svh - 82px) * 2 / 3), calc(100vw - 18px));
    font-size: 0.6rem;
  }

  .invite-content,
  .wait-content,
  .name-content {
    gap: clamp(9px, 2.4svh, 14px);
  }

  .invite-content h2,
  .wait-content h2,
  .name-content h2 {
    font-size: clamp(1.22rem, 5.2vw, 1.7rem);
  }

  .invite-content > p,
  .wait-content > p,
  .name-content p {
    font-size: clamp(0.76rem, 3vw, 0.88rem);
    line-height: 1.32;
  }

  .qr-code {
    width: min(205px, 54vw, 29svh);
  }

  .next-card-button {
    min-height: 40px;
    padding: 0 16px;
    font-size: 0.82rem;
  }
}
