:root {
  --paper: #f3ead6;
  --paper-dark: #e7dcc2;
  --ink: #241c16;
  --ink-soft: #3d3228;
  --red: #c45c4a;
  --line: #c9d6e2;
  --crease: #cbbca0;
  --desk: #2b2118;
  --lamp: #f0d9a8;
  --shadow: rgba(20, 12, 8, 0.55);
  --hand: "Patrick Hand", "Segoe UI", sans-serif;
  --stamp: "Special Elite", ui-monospace, monospace;
  --script: "Caveat", cursive;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden;
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(240, 217, 168, 0.18), transparent 55%),
    radial-gradient(800px 500px at 80% 110%, rgba(0, 0, 0, 0.35), transparent 50%),
    #2b2118;
  color: var(--ink);
  font-family: var(--hand);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

button, input {
  font-family: inherit;
}

#app, .screen {
  height: 100%;
}

.screen {
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
}

.screen.active {
  display: flex;
}

.cover {
  width: min(420px, 100%);
  background: var(--paper);
  background-image:
    linear-gradient(90deg, transparent 42px, rgba(196, 92, 74, 0.55) 42px, rgba(196, 92, 74, 0.55) 44px, transparent 44px),
    repeating-linear-gradient(var(--paper) 0 31px, rgba(160, 186, 204, 0.45) 31px 32px);
  border-radius: 2px 10px 8px 2px;
  padding: 36px 28px 28px 56px;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.4) inset,
    12px 18px 40px var(--shadow);
  transform: rotate(-0.6deg);
}

.cover.slim {
  transform: rotate(0.4deg);
}

.cover-kicker {
  font-family: var(--script);
  font-size: 1.35rem;
  color: var(--red);
}

.cover h1 {
  font-family: var(--stamp);
  font-size: clamp(2.4rem, 8vw, 3.4rem);
  letter-spacing: 0.08em;
  line-height: 1.05;
  margin: 6px 0 12px;
}

.cover h2 {
  font-family: var(--stamp);
  font-size: 2rem;
  margin: 8px 0 10px;
}

.cover-sub, .cover-note, .howto-tip, .status, .dock-hint {
  color: var(--ink-soft);
  line-height: 1.35;
}

.cover-sub {
  font-size: 1.15rem;
  margin-bottom: 22px;
}

.cover-actions, .lobby-actions, .dock-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cover-note {
  margin-top: 18px;
  font-size: 1rem;
}

.linkish, .back {
  background: none;
  border: 0;
  color: var(--red);
  font-size: 1.15rem;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
  padding: 8px 0;
}

.back {
  display: block;
  margin-bottom: 4px;
}

.btn {
  appearance: none;
  border: 2px solid var(--ink);
  background: transparent;
  color: var(--ink);
  font-size: 1.25rem;
  padding: 10px 16px;
  border-radius: 3px;
  cursor: pointer;
  letter-spacing: 0.02em;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-ink {
  background: var(--ink);
  color: var(--paper);
}

.btn-ink:hover:not(:disabled),
.btn-ghost:hover:not(:disabled) {
  transform: translateY(-1px);
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.join-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#input-code {
  font-family: var(--stamp);
  font-size: 2.4rem;
  letter-spacing: 0.35em;
  text-transform: uppercase;
  text-align: center;
  border: 0;
  border-bottom: 2px dashed var(--ink);
  background: transparent;
  padding: 8px 0 4px 0.35em;
  color: var(--ink);
  width: 100%;
  outline: none;
}

.room-code {
  font-family: var(--stamp);
  font-size: clamp(3rem, 12vw, 4.2rem);
  letter-spacing: 0.28em;
  text-align: left;
  padding-left: 0.1em;
}

.status {
  margin-top: 14px;
  min-height: 1.2em;
}

.status.error {
  color: var(--red);
}

#screen-table {
  position: relative;
  flex-direction: column;
  padding: 0;
  gap: 0;
  width: 100%;
}

.hud {
  width: min(720px, 100%);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 10px 16px 6px;
  color: var(--lamp);
  font-size: 1.1rem;
}

.hud-code {
  font-family: var(--stamp);
  letter-spacing: 0.18em;
  opacity: 0.8;
  margin-right: 10px;
}

.hud-turn {
  font-family: var(--script);
  font-size: 1.35rem;
}

.hud-right {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.btn-sound {
  appearance: none;
  background: none;
  border: 0;
  color: var(--lamp);
  font-family: var(--script);
  font-size: 1.15rem;
  cursor: pointer;
  padding: 0;
  opacity: 0.85;
}

.btn-sound:hover {
  opacity: 1;
}

.hud-score {
  font-family: var(--stamp);
  font-size: 0.95rem;
  letter-spacing: 0.06em;
  opacity: 0.9;
}

.desk {
  flex: 1;
  width: 100%;
  display: flex;
  justify-content: center;
  min-height: 0;
  padding: 0 10px;
}

.sheet-wrap {
  height: 100%;
  width: min(720px, 100%);
  filter: drop-shadow(10px 16px 22px var(--shadow));
}

.sheet {
  position: relative;
  height: 100%;
  width: 100%;
  background: var(--paper);
  border-radius: 3px 8px 7px 3px;
  overflow: hidden;
}

#field {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
  touch-action: none;
}

.crease {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 10px;
  margin-top: -5px;
  background: linear-gradient(
    to bottom,
    transparent,
    rgba(80, 60, 40, 0.18) 40%,
    rgba(255, 255, 255, 0.28) 50%,
    rgba(80, 60, 40, 0.2) 60%,
    transparent
  );
  z-index: 2;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 12px;
}

.crease span {
  font-family: var(--script);
  font-size: 1.05rem;
  color: rgba(36, 28, 22, 0.45);
  background: var(--paper);
  padding: 0 6px;
  transform: translateY(-10px);
}

.stamp {
  position: absolute;
  z-index: 4;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) rotate(-8deg);
  font-family: var(--stamp);
  font-size: clamp(2rem, 8vw, 3.2rem);
  letter-spacing: 0.12em;
  padding: 8px 14px;
  border: 4px solid currentColor;
  pointer-events: none;
}

.stamp.hit { color: #b33b2c; }
.stamp.miss { color: #5a6a78; }
.stamp.graze { color: #b07a2a; }
.stamp.show {
  animation: stamp-in 0.55s ease-out;
}

@keyframes stamp-in {
  0% { transform: translate(-50%, -50%) rotate(-18deg) scale(1.4); opacity: 0; }
  60% { transform: translate(-50%, -50%) rotate(-6deg) scale(0.96); opacity: 1; }
  100% { transform: translate(-50%, -50%) rotate(-8deg) scale(1); opacity: 1; }
}

.sheet.folding {
  animation: fold-flash 0.55s ease-in-out;
}

@keyframes fold-flash {
  0% { filter: none; }
  40% { filter: brightness(0.86) contrast(1.05); transform: rotateX(12deg); }
  100% { filter: none; transform: none; }
}

.sheet-wrap {
  perspective: 900px;
}

.dock {
  width: min(720px, 100%);
  padding: 8px 16px calc(12px + env(safe-area-inset-bottom));
  color: var(--lamp);
}

.dock-hint {
  color: rgba(240, 217, 168, 0.85);
  margin-bottom: 8px;
  min-height: 1.3em;
  font-size: 1.05rem;
}

.dock-row {
  flex-direction: row;
  flex-wrap: wrap;
}

.dock-row .btn {
  flex: 1;
  min-width: 90px;
  color: var(--lamp);
  border-color: var(--lamp);
  font-size: 1.1rem;
  padding: 8px 10px;
}

.dock-row .btn-ink {
  background: var(--lamp);
  color: var(--desk);
  border-color: var(--lamp);
}

.veil {
  position: absolute;
  inset: 0;
  background: rgba(20, 12, 8, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 8;
  padding: 20px;
}

.veil[hidden], .stamp[hidden] {
  display: none !important;
}

.veil-card {
  width: min(380px, 100%);
  background: var(--paper);
  padding: 28px 24px;
  box-shadow: 0 16px 40px var(--shadow);
}

.veil-card h2, .veil-card p {
  margin-bottom: 10px;
}

.veil-card .lobby-actions {
  margin-top: 16px;
}

.end-kicker {
  font-family: var(--script);
  color: var(--red);
  font-size: 1.4rem;
}

#howto {
  border: 0;
  padding: 0;
  background: transparent;
  max-width: 420px;
}

#howto::backdrop {
  background: rgba(20, 12, 8, 0.65);
}

.howto-inner {
  background: var(--paper);
  padding: 26px 24px;
  box-shadow: 0 16px 40px var(--shadow);
}

.howto-inner h2 {
  font-family: var(--stamp);
  margin-bottom: 12px;
}

.howto-inner ol {
  padding-left: 22px;
  margin-bottom: 12px;
}

.howto-inner li {
  margin: 8px 0;
  line-height: 1.3;
  font-size: 1.12rem;
}

.howto-inner .btn {
  margin-top: 12px;
  width: 100%;
}

@media (max-width: 420px) {
  .cover {
    padding: 28px 18px 22px 48px;
  }
  .dock-row .btn {
    font-size: 1rem;
  }
}
