/* ================================================================
   PAPERWING — origami papercraft UI
   Palette: warm washi cream, sumi ink, hanko red, pastel washes
   ================================================================ */

:root {
  --paper: #f7f1e3;
  --paper-deep: #efe5cf;
  --ink: #3a3330;
  --ink-soft: #7a6f66;
  --hanko: #d1422f;
  --hanko-dark: #a93322;
  --wash-teal: #9cc5b8;
  --wash-rose: #eebcab;
  --shadow: rgba(58, 51, 48, 0.25);
  --font-display: "Kaisei Decol", serif;
  --font-body: "Zen Maru Gothic", sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden;
  background: #f3d9c4;
  font-family: var(--font-body);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: pointer;
}

/* ---- paper grain over everything, very subtle ---- */
#grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 60;
  opacity: 0.5;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 0.96  0 0 0 0 0.93  0 0 0 0 0.87  0 0 0 0.05 0'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
}

.hidden { display: none !important; }

/* ===================== HUD ===================== */
#hud {
  position: fixed;
  top: max(18px, env(safe-area-inset-top));
  left: 0;
  right: 0;
  text-align: center;
  z-index: 10;
  pointer-events: none;
}

#score {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(56px, 10vmin, 96px);
  line-height: 1;
  color: var(--paper);
  text-shadow:
    0 2px 0 var(--shadow),
    0 6px 18px rgba(58, 51, 48, 0.35);
  transition: transform 0.12s ease;
}

#score.pop { transform: scale(1.22) rotate(-3deg); }

#best-line {
  margin-top: 2px;
  font-size: 13px;
  letter-spacing: 0.3em;
  font-weight: 700;
  color: rgba(247, 241, 227, 0.85);
  text-shadow: 0 1px 4px rgba(58, 51, 48, 0.4);
}

/* ===================== corner chips ===================== */
#corner-buttons {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  display: flex;
  gap: 8px;
  z-index: 30;
}

.chip {
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 4px 14px 6px 12px;
  background: var(--paper);
  color: var(--ink);
  font-size: 16px;
  font-family: var(--font-body);
  cursor: pointer;
  box-shadow: 0 3px 0 var(--shadow);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.chip:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--shadow); }
.chip.off { color: var(--ink-soft); text-decoration: line-through; }

/* ===================== screens ===================== */
.screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
}

/* torn-paper card */
.paper-card {
  position: relative;
  width: min(380px, 92vw);
  background: var(--paper);
  padding: 38px 30px 28px;
  text-align: center;
  border-radius: 3px 22px 5px 18px;
  box-shadow:
    0 1px 0 #fff inset,
    0 14px 0 -6px var(--paper-deep),
    0 26px 40px rgba(58, 51, 48, 0.35);
  animation: card-in 0.5s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}

.paper-card.slim { width: min(300px, 88vw); }

@keyframes card-in {
  from { transform: translateY(36px) rotate(2.5deg); opacity: 0; }
  to   { transform: translateY(0) rotate(0deg); opacity: 1; }
}

/* red seal stamp */
.hanko {
  position: absolute;
  top: -20px;
  right: 22px;
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--hanko);
  color: var(--paper);
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 700;
  border-radius: 8px 10px 9px 11px;
  transform: rotate(8deg);
  box-shadow: 0 4px 0 var(--hanko-dark), 0 8px 14px rgba(169, 51, 34, 0.4);
}

.hanko-red { background: var(--ink); box-shadow: 0 4px 0 #241f1d, 0 8px 14px rgba(0,0,0,0.35); }

.title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 54px;
  line-height: 0.95;
  letter-spacing: 0.04em;
  color: var(--ink);
}

.title::after {
  content: "紙 の 翼";
  display: block;
  margin-top: 10px;
  font-size: 14px;
  letter-spacing: 0.8em;
  color: var(--hanko);
  font-weight: 400;
}

.subtitle {
  margin-top: 12px;
  font-size: 13px;
  color: var(--ink-soft);
}

.rule {
  margin: 18px auto 14px;
  width: 70%;
  height: 2px;
  background:
    repeating-linear-gradient(90deg, var(--ink-soft) 0 8px, transparent 8px 14px);
  opacity: 0.45;
}

.howto {
  font-size: 13px;
  line-height: 2;
  color: var(--ink-soft);
}

.key {
  display: inline-block;
  padding: 1px 9px;
  margin: 0 2px;
  background: var(--paper-deep);
  border: 1.5px solid var(--ink-soft);
  border-radius: 6px;
  box-shadow: 0 2px 0 var(--ink-soft);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--ink);
}

/* ===================== buttons ===================== */
.big-btn {
  margin-top: 20px;
  width: 100%;
  padding: 14px 18px;
  border: none;
  border-radius: 4px 16px 5px 14px;
  background: var(--hanko);
  color: var(--paper);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 19px;
  letter-spacing: 0.12em;
  cursor: pointer;
  box-shadow: 0 5px 0 var(--hanko-dark), 0 10px 18px rgba(169, 51, 34, 0.35);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.big-btn:hover { transform: translateY(-1px); }
.big-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--hanko-dark); }

.small-btn {
  padding: 8px 14px;
  border: none;
  border-radius: 4px 10px 4px 9px;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.1em;
  cursor: pointer;
  box-shadow: 0 3px 0 #241f1d;
}

.small-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #241f1d; }

.credits {
  margin-top: 18px;
  font-size: 10.5px;
  letter-spacing: 0.15em;
  color: var(--ink-soft);
  opacity: 0.8;
}

.hint {
  margin-top: 12px;
  font-size: 11px;
  letter-spacing: 0.2em;
  color: var(--ink-soft);
}

/* ===================== game over ===================== */
.over-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 40px;
  line-height: 1.05;
  color: var(--ink);
}

.score-row {
  display: flex;
  gap: 12px;
  margin-top: 18px;
}

.score-box {
  flex: 1;
  background: var(--paper-deep);
  border-radius: 3px 12px 4px 10px;
  padding: 10px 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.score-box .label {
  font-size: 10px;
  letter-spacing: 0.3em;
  color: var(--ink-soft);
  font-weight: 700;
}

.score-box span:last-child {
  font-family: var(--font-display);
  font-size: 34px;
  font-weight: 700;
  color: var(--ink);
}

.new-best {
  margin-top: 12px;
  display: inline-block;
  padding: 4px 16px;
  background: var(--hanko);
  color: var(--paper);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.25em;
  border-radius: 3px 10px 3px 9px;
  transform: rotate(-2deg);
  animation: tag-pulse 1.2s ease infinite;
}

@keyframes tag-pulse {
  0%, 100% { transform: rotate(-2deg) scale(1); }
  50% { transform: rotate(-2deg) scale(1.07); }
}

/* ===================== name form ===================== */
.name-form { margin-top: 16px; }

.name-form label {
  display: block;
  font-size: 12px;
  color: var(--ink-soft);
  margin-bottom: 8px;
}

.name-row {
  display: flex;
  gap: 8px;
  justify-content: center;
}

#initials {
  width: 110px;
  padding: 8px 10px;
  border: 2px solid var(--ink-soft);
  border-radius: 4px 10px 4px 9px;
  background: #fffdf7;
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.35em;
  text-align: center;
  text-transform: uppercase;
  color: var(--ink);
  outline: none;
}

#initials:focus { border-color: var(--hanko); }

/* ===================== leaderboard ===================== */
.board, .mini-board { margin-top: 16px; text-align: left; }

.board-title {
  font-size: 10px;
  letter-spacing: 0.35em;
  font-weight: 700;
  color: var(--ink-soft);
  text-align: center;
  margin-bottom: 8px;
}

.board-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 3px 10px;
  font-size: 14px;
  border-radius: 3px 8px 3px 7px;
}

.board-row.me {
  background: var(--hanko);
  color: var(--paper);
}

.board-row.me .board-name, .board-row.me .board-rank { color: var(--paper); }

.board-rank {
  width: 22px;
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-soft);
}

.board-name {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 0.2em;
}

.board-dots {
  flex: 1;
  border-bottom: 2px dotted rgba(122, 111, 102, 0.4);
  transform: translateY(-3px);
}

.board-score { font-weight: 700; }

.board-empty {
  text-align: center;
  font-size: 12px;
  color: var(--ink-soft);
  font-style: italic;
}

.mini-board .board-row { font-size: 12.5px; padding: 2px 8px; }

/* ===================== small screens ===================== */
@media (max-height: 700px) {
  .paper-card { padding: 30px 24px 22px; }
  .title { font-size: 42px; }
  .mini-board .board-row:nth-child(n+6) { display: none; }
}
