/* ====== Base ====== */
:root {
  --bg: #301049;
  --text: #f8f5d7;
  --mint: #d3f6d7;
  --mint-disabled: #bde8c2;
  --orange: #ffd494;
  --orange-dim: #f3bf77;
  --p1: #5a2a8a;
  --p2: #ff4fa6;
  --btn: #a6c4e0;
  --btn-hover: #ff9aa2;
  --shadow: rgba(0,0,0,0.35);
  --ui-font: 'Press Start 2P', system-ui, -apple-system, sans-serif;
  --cn-font: 'STXihei','Heiti SC','PingFang SC','Microsoft YaHei',sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: var(--ui-font);
}

/* ====== Title ====== */
.top-header {
  text-align: center;
  padding: 24px 10px 32px; 
}
.title {
  margin: 10;
  font-size: clamp(30px, 4vw, 56px);
  text-shadow: 0 4px 0 #000;
}

/* ====== Instruction Area ====== */
.instruction-area {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 0 auto 22px auto; /* extra space below instruction area */
  width: 100%;
}
.instruction-inner {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  justify-content: center;
}
.avatar-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-width: 60px;
}
.avatar {
  width: clamp(34px, 8vw, 56px);
  height: clamp(34px, 8vw, 56px);
  display: inline-block;
  animation: float 3s ease-in-out infinite;
}
.avatar.p2 { animation-duration: 3.8s; }
@keyframes float {
  0% { transform: translateY(0px); }
  50% { transform: translateY(-3px); }
  100% { transform: translateY(0px); }
}
.avatar-svg .eye {
  transform-origin: center;
  animation: wink 5s infinite;
}
.avatar.p2 .eye { animation-delay: 1.2s; }
@keyframes wink {
  0%, 90%, 100% { transform: scaleY(1); }
  92% { transform: scaleY(0.1); }
  94% { transform: scaleY(1); }
}
.name-tag {
  font-size: clamp(9px, 1.5vw, 12px);
  color: var(--text);
  opacity: 0.9;
}
#instruction {
  text-align: center;
  font-size: clamp(10px, 2.2vw, 16px);
  color: var(--text);
  min-height: 1.8em;
  white-space: nowrap;
  max-width: 320px;
  word-break: break-word;
}
.typewriter {
  overflow: hidden;
  border-right: .15em solid rgba(255,255,255,0.6);
  white-space: nowrap;
  animation: caret 1.1s steps(1) infinite;
}
@keyframes caret {
  50% { border-color: transparent; }
}
@media (max-width: 600px) {
  .instruction-inner {
    flex-direction: column;
    gap: 8px;
  }
  .avatar-box {
    min-width: 0;
  }
}

/* ====== Timer Circles ====== */
.circle-timer {
  width: 64px; height: 64px;
  border-radius: 50%;
  background: #f9eaea;
  color: #000;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--ui-font);
  border: 5px solid #74c0fc;
  box-shadow: inset 0 0 0 4px #fff, 0 3px 8px var(--shadow);
  user-select: none;
}
.circle-timer.small { width: 56px; height: 56px; border-width: 4px; }
.hidden { display: none !important; }

/* ====== Buttons ====== */
.buttons-row {
  display: flex;
  justify-content: center;
  margin: 28px 0 18px 0; /* extra space above and below buttons */
}
.buttons {
  display: flex;
  gap: 16px;
  justify-content: center;
  align-items: center;
}
.pix-btn {
  background: var(--btn);
  border: 3px solid #000;
  border-radius: 10px;
  color: #101010;
  padding: 10px 12px;
  font-family: var(--ui-font);
  font-size: clamp(10px, 1.6vw, 14px);
  box-shadow: 0 4px 0 #183d5c, 0 6px 8px var(--shadow);
  cursor: pointer;
  transition: transform 0.06s ease, filter .15s ease;
}
.pix-btn:hover { filter: brightness(1.06) saturate(1.1); background: var(--btn-hover); }
.pix-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 #183d5c; }
.pix-btn:disabled {
  filter: grayscale(60%) brightness(0.85); cursor: not-allowed; transform: none;
}
.pix-btn.danger { background: #ed8a8a; }
.pix-btn.speak { background: #9bf6ff; }

/* ====== Board ====== */
.board-wrap {
  position: relative;
  padding: 8px 12px 18px;
}
#topTimer {
  position: absolute;
  left: 200px;
  top: -72px; /* adjust as needed for spacing above the board */
  z-index: 10;
  transition: opacity 0.2s;
}
.board {
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 6px;
  width: min(1200px, 96vw);
}
.board.disabled { filter: grayscale(25%) brightness(0.95); pointer-events: none; }

.cell {
  position: relative;
  padding: clamp(9px, 1.2vw, 12px) clamp(10px, 1.4vw, 16px);
  min-height: 42px;
  background: var(--mint);
  border: 3px solid #000;
  border-radius: 14px; /* round edges */
  font-family: var(--cn-font);
  color: #101010;
  font-size: clamp(13px, 1.8vw, 18px);
  font-weight: 500;
  text-align: center;
  box-shadow: 0 2px 0 #000, 0 4px 8px var(--shadow);
  transition: background 0.2s, box-shadow 0.2s;
}
.cell:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #1c6b3e;
}
.cell.disabled {
  background: var(--mint-disabled);
  pointer-events: none;
}
.cell.highlight {
  background: var(--orange);
  box-shadow: 0 0 0 3px #000 inset, 0 0 12px #f7c271;
}
.cell.highlight.modal-open {
  background: var(--orange-dim);
  filter: saturate(0.9);
}

/* Canvas/SVG mark container */
.cell {
  position: relative;
  /* ...existing styles... */
}

.cell {
  position: relative;
}
.cell .mark-layer {
  z-index: 3;
}
.cell {
  z-index: 4;
}
.cell {
  position: relative;
  overflow: visible; /* Ensure SVG is not clipped */
}

.cell .mark-layer {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 3;
}

/* Pencil stroke animation generic */
.mark-stroke {
  stroke-dasharray: 360;
  stroke-dashoffset: 360;
  animation: draw 0.7s cubic-bezier(.7,.1,.3,1) forwards;
}
@keyframes draw {
  to { stroke-dashoffset: 0; }
}

/* ====== Modal ====== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(48,16,73,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal.hidden { display: none; }
.modal-content {
  background: #f5d0f6;
  border-radius: 16px;
  box-shadow: 0 8px 32px #0008;
  padding: 24px 18px 18px;
  min-width: 260px;
  max-width: 90vw;
  position: relative;
}
.zoom-in { animation: zoom .25s ease-out; }
@keyframes zoom {
  0% { transform: scale(0.7); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.modal-header {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-bottom: 12px;
}
.attempt-text {
  font-size: clamp(10px, 2vw, 16px);
  color: #301049;
  font-weight: bold;
}
.modal-word {
  text-align: center;
  font-size: clamp(28px, 4vw, 48px);
  color: #301049;
  margin: 12px 0 18px 0;
}
.modal-actions { display: flex; justify-content: center; margin-top: 6px; }
.modal-result { text-align: center; margin-top: 8px; min-height: 1.5em; color: #000; }

/* Modal shake on error */
.shake {
  animation: shake 0.3s cubic-bezier(.36,.07,.19,.97) both;
}
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-8px); }
  40%, 60% { transform: translateX(8px); }
}

/* ====== Winner Overlay ====== */
.winner-overlay {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.45);
  z-index: 60;
}
.winner-text {
  background: #fff2a8; color: #000;
  border: 4px solid #000;
  border-radius: 50px;
  font-size: clamp(30px, 4vw, 68px);
  padding: 14px 18px;
  box-shadow: 0 6px 0 #183d5c, 0 8px 12px rgba(0,0,0,0.35);
}


/* ====== Utility ====== */
[aria-live="polite"] { outline: none; }

/* ====== Menu (landing page) ====== */
.menu-wrap { max-width: 880px; margin: 0 auto; padding: 0 16px 60px; text-align: center; }
.menu-tagline { font-size: clamp(11px, 1.6vw, 15px); line-height: 1.8; margin: 0 0 34px; color: var(--mint); }
.menu-cards { display: flex; gap: 22px; justify-content: center; flex-wrap: wrap; }
.menu-card {
  display: block; width: 300px; max-width: 90vw; text-decoration: none; color: #101010;
  background: var(--mint); border: 4px solid #000; border-radius: 18px; padding: 26px 22px;
  box-shadow: 0 4px 0 #000, 0 8px 16px var(--shadow); transition: transform .15s, box-shadow .15s;
}
.menu-card:hover { transform: translateY(-4px); box-shadow: 0 8px 0 #000, 0 12px 22px var(--shadow); background: var(--orange); }
.menu-card-icon { font-size: 44px; margin-bottom: 12px; }
.menu-card-title { font-size: 16px; margin-bottom: 12px; }
.menu-card-desc { font-family: var(--cn-font); font-size: 14px; line-height: 1.5; font-weight: 600; }
.menu-note { margin-top: 34px; font-size: clamp(9px, 1.2vw, 11px); color: var(--orange); line-height: 1.8; }

/* ====== Header link / mode badge ====== */
.title-link { color: inherit; text-decoration: none; }
.mode-badge { font-size: clamp(10px, 1.4vw, 16px); color: var(--p2); vertical-align: middle; }

/* ====== Lobby / waiting room ====== */
.lobby, .waiting { max-width: 900px; margin: 0 auto; padding: 0 16px 60px; text-align: center; }
.lobby-cols { display: flex; gap: 22px; justify-content: center; flex-wrap: wrap; }
.lobby-card {
  background: var(--mint); color: #101010; border: 4px solid #000; border-radius: 18px;
  padding: 22px; width: 380px; max-width: 92vw; box-shadow: 0 4px 0 #000, 0 8px 16px var(--shadow);
  display: flex; flex-direction: column; align-items: stretch; gap: 12px;
}
.lobby-h { font-size: 15px; margin: 0; }
.lobby-sub { font-family: var(--cn-font); font-weight: 600; font-size: 13px; line-height: 1.5; margin: 0; }
.vocab-input {
  font-family: var(--cn-font); font-size: 15px; min-height: 150px; resize: vertical;
  border: 3px solid #000; border-radius: 12px; padding: 10px; width: 100%;
}
.vocab-count { font-family: var(--cn-font); font-size: 12px; font-weight: 700; text-align: right; opacity: .75; }
.code-input {
  font-family: var(--ui-font); font-size: 28px; text-align: center; letter-spacing: 8px;
  border: 3px solid #000; border-radius: 12px; padding: 12px; width: 100%; text-transform: uppercase;
}
.lobby-error { margin-top: 18px; color: var(--btn-hover); font-family: var(--cn-font); font-weight: 700; min-height: 22px; }

.room-code {
  font-size: clamp(40px, 9vw, 72px); letter-spacing: 10px; color: var(--orange);
  text-shadow: 0 4px 0 #000; margin: 10px 0 16px;
}
.waiting-status { display: flex; gap: 26px; justify-content: center; margin: 26px 0 10px; }
.player-dot { font-size: 16px; color: var(--mint); }
.player-dot.off { opacity: .4; }
.waiting-msg { font-family: var(--cn-font); font-weight: 700; font-size: 15px; margin: 8px 0; }
.you-are { font-family: var(--cn-font); font-weight: 700; margin-top: 16px; }
.p1-text { color: var(--p1); } .p2-text { color: var(--p2); }
.pix-btn.small { font-size: 11px; padding: 8px 12px; }

.hidden { display: none !important; }

/* Play-again button inside winner overlay */
.winner-overlay .pix-btn { margin-top: 26px; }

/* ====== Lobby: "use random" level picker ====== */
.random-box { background: rgba(0,0,0,0.05); border: 2px dashed #000; border-radius: 12px; padding: 10px; }
.random-label { font-family: var(--ui-font); font-size: 11px; margin-bottom: 8px; }
.random-row { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.pix-btn.tiny { font-size: 12px; padding: 8px 12px; min-width: 46px; }
.pix-btn.tiny.mix { background: var(--orange); }
.level-hint { font-family: var(--cn-font); font-size: 11px; font-weight: 700; margin-top: 8px; text-align: center; line-height: 1.5; opacity: .8; }

/* ====== Microphone helper (lobby) ====== */
.mic-help { max-width: 560px; margin: 26px auto 0; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.mic-link { font-family: var(--cn-font); font-weight: 700; font-size: 13px; color: var(--orange); text-decoration: underline; }
.mic-status { font-family: var(--cn-font); font-weight: 700; font-size: 13px; line-height: 1.5; min-height: 18px; }
.mic-status.ok   { color: #7CFC9A; }
.mic-status.err  { color: var(--btn-hover); }
.mic-status.warn { color: var(--orange); }
.mic-details { font-family: var(--cn-font); font-size: 13px; color: var(--text); max-width: 540px; }
.mic-details summary { cursor: pointer; font-weight: 700; }
.mic-steps { margin-top: 8px; line-height: 1.6; text-align: left; background: rgba(0,0,0,0.18); border-radius: 10px; padding: 10px 12px; }
.mic-steps em { color: var(--orange); font-style: normal; }
