:root {
  --bg-top: #ffd28b;
  --bg-bottom: #fff5de;
  --ink: #2f1e08;
  --accent: #f46d2e;
  --accent-2: #f1a82b;
  --line: rgba(77, 45, 10, 0.2);
  --empty: rgba(255, 255, 255, 0.82);
  --filled: #fff0cc;
  --cell-width: 56px;
  --cell-height: 28px;
  --cell-padding-x: 4px;
  --cell-padding-y: 3px;
  --banner-height: 58px;
  --dock-height: 74px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
}

body {
  font-family: "Noto Sans", sans-serif;
  color: var(--ink);
  background: linear-gradient(170deg, var(--bg-top) 0%, var(--bg-bottom) 60%);
  overflow: hidden;
}

[hidden] {
  display: none !important;
}

.backdrop {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 12% 18%, rgba(255, 255, 255, 0.55) 0, rgba(255, 255, 255, 0) 22%),
    radial-gradient(circle at 92% 88%, rgba(244, 109, 46, 0.2) 0, rgba(244, 109, 46, 0) 26%),
    repeating-linear-gradient(
      45deg,
      rgba(255, 255, 255, 0.1) 0px,
      rgba(255, 255, 255, 0.1) 1px,
      rgba(255, 255, 255, 0) 1px,
      rgba(255, 255, 255, 0) 12px
    );
}

.top-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 30;
  min-height: var(--banner-height);
  padding: 10px 12px calc(10px + env(safe-area-inset-top));
  background: linear-gradient(120deg, rgba(251, 133, 0, 0.96), rgba(243, 104, 12, 0.92));
  color: #fff7e8;
  box-shadow: 0 6px 22px rgba(100, 41, 3, 0.22);
  animation: slideDown 360ms ease-out;
  overflow: hidden;
}

.progress-bar-track {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 5px;
  background: linear-gradient(90deg, rgba(74, 31, 3, 0.18), rgba(255, 255, 255, 0.12));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14);
}

.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #ff8c00, #ffcc44);
  transition: width 0.6s ease;
  border-radius: 0 999px 999px 0;
  box-shadow: 0 0 10px rgba(255, 200, 50, 0.55);
}

.top-banner-row {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr) max-content;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-width: 0;
}

.banner-section {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.banner-left {
  font-family: "Tiro Devanagari Sanskrit", serif;
  font-size: 0.84rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  justify-self: start;
}

.banner-middle {
  font-size: 0.67rem;
  font-weight: 700;
  justify-content: center;
  overflow: hidden;
}

.banner-right {
  gap: 8px;
  font-size: 0.75rem;
  justify-self: end;
}

.writing-now {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.67rem;
  font-weight: 600;
  opacity: 0.88;
  white-space: nowrap;
}

.writing-now-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #ffe066;
  box-shadow: 0 0 5px rgba(255, 220, 50, 0.8);
  animation: writingPulse 1.6s ease-in-out infinite;
  flex-shrink: 0;
}

@keyframes writingPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.7); }
}

.counter-flash {
  animation: counterFlash 0.5s ease;
}

@keyframes counterFlash {
  0% { opacity: 1; }
  30% { opacity: 0.4; }
  100% { opacity: 1; }
}

.banner-brand {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  color: inherit;
  cursor: pointer;
}

.banner-brand:hover {
  opacity: 0.85;
}

.banner-emoji {
  display: inline-block;
  font-size: 0.92em;
  line-height: 1;
  vertical-align: -0.04em;
}

.banner-link {
  color: #fff7e8;
  text-decoration: none;
  font-weight: 700;
  opacity: 0.94;
}

.banner-link:hover {
  opacity: 1;
}

.banner-link-button {
  appearance: none;
  border: none;
  background: transparent;
  padding: 0;
  cursor: pointer;
  font: inherit;
  white-space: nowrap;
}

#remainingCounter {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
}

@media (max-width: 479px) {
  #remainingCounter {
    display: none;
  }
}

.main-shell {
  position: fixed;
  inset: 0;
  padding-top: calc(var(--banner-height) + env(safe-area-inset-top));
  padding-bottom: env(safe-area-inset-bottom);
}

#gridViewport {
  width: 100%;
  height: 100%;
  overflow: auto;
  overscroll-behavior: contain;
  touch-action: pan-x pan-y;
  -webkit-overflow-scrolling: touch;
  scroll-padding-bottom: calc(var(--dock-height) + 22px + env(safe-area-inset-bottom));
}

#gridCanvas {
  position: relative;
  transform-origin: top left;
  margin-bottom: calc(var(--dock-height) + 22px + env(safe-area-inset-bottom));
}

.cell {
  position: absolute;
  border: 1px solid var(--line);
  width: var(--cell-width);
  height: var(--cell-height);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  padding: var(--cell-padding-y) var(--cell-padding-x);
  line-height: 1;
  text-align: center;
  overflow: hidden;
  font-size: 0.72rem;
  white-space: nowrap;
  text-wrap: nowrap;
}

.cell-empty {
  cursor: pointer;
  color: rgba(77, 45, 10, 0.8);
  background: var(--empty);
  font-weight: 700;
  font-size: 0.92rem;
}

.cell-empty:active {
  transform: scale(0.95);
}

.cell-filled {
  background: var(--filled);
  color: #5b2a00;
  font-weight: 600;
  font-size: var(--fit-font-size, 0.72rem);
  text-wrap: nowrap;
  white-space: nowrap;
}

.cell-highlight {
  box-shadow: 0 0 0 2px #ffd36c inset, 0 0 20px rgba(255, 174, 0, 0.85);
  animation: pulse 1.2s ease-in-out 2;
}

.cell-mine {
  background: linear-gradient(135deg, #ffe7a2, #ffd385);
  border-color: rgba(196, 100, 16, 0.78);
  box-shadow: inset 0 0 0 1px rgba(255, 248, 218, 0.92), 0 0 0 2px rgba(244, 109, 46, 0.2);
}

.cell-focused {
  outline: 2px solid #f46d2e;
  outline-offset: -2px;
  z-index: 1;
}

#gridViewport:focus {
  outline: none;
}

#gridCanvas:focus {
  outline: none;
}


.bottom-dock {
  position: fixed;
  left: 50%;
  bottom: calc(12px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: calc(100vw - 16px);
  padding: 6px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.7);
  background: rgba(255, 255, 255, 0.62);
  backdrop-filter: blur(8px);
  box-shadow: 0 8px 25px rgba(96, 58, 9, 0.18);
  animation: riseUp 420ms ease-out;
}

.filled-counter {
  padding: 7px 11px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.85);
  color: #3e2306;
  font-weight: 700;
  font-size: 0.86rem;
  white-space: nowrap;
}

.my-counter {
  position: fixed;
  left: 12px;
  bottom: calc(var(--dock-height) + 16px + env(safe-area-inset-bottom));
  z-index: 41;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255, 232, 176, 0.92);
  border: 1px solid rgba(200, 120, 30, 0.25);
  backdrop-filter: blur(6px);
  color: #7a3d00;
  font-weight: 600;
  font-size: 0.8rem;
  white-space: nowrap;
  pointer-events: none;
}

.share-btn,
.random-btn {
  appearance: none;
  border: none;
  border-radius: 999px;
  padding: 7px 11px;
  white-space: nowrap;
  font-weight: 700;
  font-size: 0.83rem;
}

.share-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #6d3704;
  background: rgba(255, 247, 232, 0.92);
  border: 1px solid rgba(145, 79, 8, 0.14);
  box-shadow: 0 5px 12px rgba(109, 55, 4, 0.12);
}

.random-btn {
  color: #fff;
  background: linear-gradient(110deg, var(--accent), var(--accent-2));
  box-shadow: 0 6px 14px rgba(126, 66, 3, 0.28);
}

.share-btn-icon {
  font-size: 0.94rem;
  line-height: 1;
}

.random-btn:disabled,
.share-btn:disabled {
  opacity: 0.6;
}

.picker {
  position: fixed;
  z-index: 50;
  min-width: 196px;
  max-width: min(90vw, 260px);
  max-height: min(55vh, 320px);
  overflow: auto;
  padding: 6px;
  border-radius: 12px;
  background: rgba(255, 250, 242, 0.96);
  border: 1px solid rgba(132, 71, 6, 0.24);
  box-shadow: 0 12px 26px rgba(66, 38, 7, 0.26);
}

.turnstile-modal {
  position: fixed;
  inset: 0;
  z-index: 58;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(49, 24, 3, 0.28);
  backdrop-filter: blur(6px);
}

.turnstile-card {
  width: min(calc(100vw - 32px), 360px);
  padding: 18px 18px 16px;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.76);
  background: rgba(255, 251, 245, 0.96);
  box-shadow: 0 18px 42px rgba(73, 38, 5, 0.22);
}

.turnstile-title {
  margin-bottom: 6px;
  font-family: "Tiro Devanagari Sanskrit", serif;
  font-size: 1rem;
  font-weight: 700;
  color: #592f03;
}

.turnstile-copy {
  margin: 0 0 14px;
  font-size: 0.82rem;
  line-height: 1.45;
  color: rgba(65, 36, 6, 0.84);
}

.turnstile-widget {
  display: flex;
  justify-content: center;
}

.turnstile-close {
  appearance: none;
  margin-top: 12px;
  border: none;
  background: transparent;
  padding: 0;
  font-weight: 700;
  font-size: 0.82rem;
  color: #8a4307;
}

.about-panel {
  position: fixed;
  top: calc(var(--banner-height) + env(safe-area-inset-top) + 10px);
  right: 12px;
  z-index: 45;
  width: min(calc(100vw - 24px), 420px);
}

.about-card {
  padding: 14px 16px;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.72);
  background: rgba(255, 251, 245, 0.94);
  backdrop-filter: blur(12px);
  box-shadow: 0 14px 36px rgba(73, 38, 5, 0.2);
  color: #4b2a05;
}

.about-title {
  margin-bottom: 8px;
  font-family: "Tiro Devanagari Sanskrit", serif;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.about-card p {
  margin: 0 0 10px;
  font-size: 0.82rem;
  line-height: 1.45;
}

.about-signoff {
  margin-bottom: 0;
  font-weight: 700;
}

.share-panel {
  position: fixed;
  left: 50%;
  bottom: calc(var(--dock-height) + 18px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 45;
  width: min(calc(100vw - 24px), 420px);
}

.share-card {
  padding: 14px 16px;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.72);
  background: rgba(255, 251, 245, 0.96);
  backdrop-filter: blur(12px);
  box-shadow: 0 14px 36px rgba(73, 38, 5, 0.2);
  color: #4b2a05;
}

.share-title {
  margin-bottom: 8px;
  font-family: "Tiro Devanagari Sanskrit", serif;
  font-size: 1rem;
  font-weight: 700;
}

.share-preview {
  margin: 0 0 12px;
  font-size: 0.82rem;
  line-height: 1.45;
  color: rgba(65, 36, 6, 0.84);
}

.share-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.share-option {
  appearance: none;
  border: 1px solid rgba(140, 73, 6, 0.18);
  border-radius: 12px;
  padding: 9px 10px;
  background: rgba(255, 255, 255, 0.88);
  color: #562d03;
  font-weight: 700;
  font-size: 0.82rem;
  text-align: center;
}

.share-option:hover,
.share-option:active {
  background: rgba(244, 109, 46, 0.12);
}

.share-note {
  margin: 10px 0 0;
  font-size: 0.76rem;
  line-height: 1.4;
  color: rgba(77, 45, 10, 0.74);
}

.picker-option {
  width: 100%;
  border: none;
  background: transparent;
  text-align: left;
  display: block;
  padding: 8px 10px;
  border-radius: 8px;
  color: #3a2105;
  font-size: 0.86rem;
}

.picker-option:active,
.picker-option:hover {
  background: rgba(244, 109, 46, 0.14);
}

.picker-option-preferred {
  background: rgba(244, 109, 46, 0.09);
}

.picker-option-preferred .lang::after {
  content: " ✓";
  font-size: 0.68rem;
  opacity: 0.7;
}

.picker-option .lang {
  display: inline-block;
  min-width: 82px;
  margin-right: 8px;
  color: rgba(59, 33, 5, 0.72);
  font-size: 0.74rem;
}

.toast {
  position: fixed;
  left: 50%;
  top: calc(var(--banner-height) + 16px + env(safe-area-inset-top));
  transform: translateX(-50%);
  z-index: 55;
  padding: 8px 12px;
  border-radius: 10px;
  color: #fffaf3;
  font-size: 0.82rem;
  background: rgba(72, 37, 4, 0.83);
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}

.toast-share-btn {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 6px;
  padding: 3px 9px;
  background: rgba(255, 255, 255, 0.15);
  color: #fffaf3;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.toast-share-btn:hover {
  background: rgba(255, 255, 255, 0.26);
}

.milestone-overlay {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  font-family: "Tiro Devanagari Sanskrit", serif;
  font-size: clamp(1.4rem, 5vw, 2.6rem);
  font-weight: 700;
  color: #fff;
  text-align: center;
  padding: 24px;
  text-shadow: 0 2px 18px rgba(100, 41, 3, 0.6);
}

.milestone-animate {
  animation: milestoneRise 3.8s ease forwards;
}

.live-feed {
  position: fixed;
  right: 12px;
  bottom: calc(var(--dock-height) + 16px + env(safe-area-inset-bottom));
  z-index: 42;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 5px;
  pointer-events: none;
}

.live-feed-item {
  padding: 4px 10px;
  border-radius: 8px;
  background: rgba(255, 251, 245, 0.88);
  border: 1px solid rgba(200, 120, 30, 0.2);
  backdrop-filter: blur(6px);
  color: #5b2a00;
  font-size: 0.8rem;
  font-weight: 600;
  animation: feedSlideIn 0.25s ease;
  white-space: nowrap;
}

@keyframes milestoneRise {
  0% {
    opacity: 0;
    transform: scale(0.7);
  }
  15% {
    opacity: 1;
    transform: scale(1.08);
  }
  25% {
    transform: scale(1);
  }
  70% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: scale(1.04);
  }
}

@keyframes feedSlideIn {
  from {
    opacity: 0;
    transform: translateX(18px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-24px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes riseUp {
  from {
    opacity: 0;
    transform: translate(-50%, 30px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

@keyframes pulse {
  0%,
  100% {
    box-shadow: 0 0 0 2px #ffd36c inset, 0 0 8px rgba(255, 174, 0, 0.45);
  }
  50% {
    box-shadow: 0 0 0 2px #ffeb97 inset, 0 0 22px rgba(255, 174, 0, 0.95);
  }
}

@media (min-width: 768px) {
  :root {
    --cell-width: 64px;
    --cell-height: 30px;
    --cell-padding-x: 5px;
    --banner-height: 64px;
    --dock-height: 78px;
  }

  .banner-left {
    font-size: 1.16rem;
    letter-spacing: 0.02em;
  }

  .banner-middle {
    font-size: 0.94rem;
  }

  .banner-right {
    font-size: 0.88rem;
    gap: 12px;
  }

  .about-panel {
    right: 16px;
  }

  .share-panel {
    left: auto;
    right: 16px;
    transform: none;
    width: min(calc(100vw - 32px), 380px);
  }

  .live-feed {
    right: 16px;
  }

  .my-counter {
    left: 16px;
  }
}
