/* Acrostic Puzzle Mode */

.acrostic-round {
  display: none;
  position: fixed !important;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100% !important;
  height: 100% !important;
  flex-direction: column;
  background: #222222;
  z-index: 2000 !important;
  overflow: hidden !important;
  box-sizing: border-box;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.acrostic-round.visible {
  display: flex;
}

.acrostic-round .status-bar {
  flex-shrink: 0;
}

.acrostic-start {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 16px 16px 24px;
  text-align: center;
  color: #e8e4dc;
  gap: 10px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.acrostic-start h2 {
  margin: 0;
  font-size: 1.45rem;
  letter-spacing: 0.08em;
  color: #f5f0e6;
}

.acrostic-streak {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 600;
  color: #c4a35a;
  letter-spacing: 0.02em;
}

.acrostic-selected-title {
  margin: 0;
  max-width: 360px;
  font-size: 1.05rem;
  font-weight: 700;
  color: #f5ecd7;
  line-height: 1.3;
}

.acrostic-start p,
.acrostic-start-lead {
  margin: 0;
  max-width: 360px;
  line-height: 1.35;
  color: #9a9286;
  font-size: 0.78rem;
}

.acrostic-start-button {
  margin-top: 12px;
  padding: 14px 36px;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  border: 2px solid #c4a35a;
  background: #292826;
  color: #f5ecd7;
  cursor: pointer;
  border-radius: 6px;
}

.acrostic-start-button:hover {
  background: #3a3530;
}

.acrostic-temp-banner {
  font-size: 0.8rem;
  color: #c4785a;
  border: 1px solid #c4785a55;
  padding: 6px 12px;
  border-radius: 4px;
  background: #2a1f1a;
}

.acrostic-start-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 24px;
  justify-content: center;
  font-size: 0.95rem;
  color: #d8d0c4;
}

.acrostic-meta-label {
  color: #8a8276;
  margin-right: 6px;
  text-transform: uppercase;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
}

.acrostic-start-status {
  max-width: 420px;
  font-size: 0.85rem;
  color: #9a9286;
}

.acrostic-start-status.is-error {
  color: #d08070;
}

.acrostic-calendar {
  width: min(360px, 100%);
  background: #2a2826;
  border: 1px solid #3f3b36;
  border-radius: 8px;
  padding: 14px;
  text-align: center;
}

.acrostic-cal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  gap: 8px;
}

.acrostic-cal-month {
  font-weight: 600;
  color: #f0e8d8;
  font-size: 0.95rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.acrostic-cal-nav {
  width: 32px;
  height: 32px;
  border: 1px solid #4a453e;
  background: #33302c;
  color: #e8e0d4;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1.25rem;
  line-height: 1;
  padding: 0;
  margin: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-sizing: border-box;
  -webkit-appearance: none;
  appearance: none;
}

.acrostic-cal-nav:hover {
  background: #403c36;
}

.acrostic-cal-dows,
.acrostic-cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.acrostic-cal-dows {
  margin-bottom: 4px;
}

.acrostic-cal-dows span {
  font-size: 0.7rem;
  color: #8a8276;
  padding: 4px 0;
}

.acrostic-cal-day {
  aspect-ratio: 1;
  border: 1px solid transparent;
  background: transparent;
  color: #6e675c;
  border-radius: 4px;
  cursor: default;
  font-size: 0.85rem;
  padding: 0;
  position: relative;
}

.acrostic-cal-day-num {
  display: block;
  line-height: 1;
}

.acrostic-cal-star {
  position: absolute;
  top: 1px;
  right: 2px;
  font-size: 0.58rem;
  line-height: 1;
  pointer-events: none;
}

.acrostic-cal-day.completed-today .acrostic-cal-star {
  color: #c4a35a;
}

.acrostic-cal-day.completed-past .acrostic-cal-star {
  color: #9a8f78;
  opacity: 0.9;
}

.acrostic-cal-day.selected.completed-today .acrostic-cal-star {
  color: #1e1c18;
}

.acrostic-cal-day.selected.completed-past .acrostic-cal-star {
  color: #3a3228;
}

.acrostic-cal-day.empty {
  pointer-events: none;
}

.acrostic-cal-day.unavailable {
  opacity: 0.35;
  cursor: default;
}

.acrostic-cal-day.has-puzzle,
.acrostic-cal-day.is-today:not(.unavailable) {
  cursor: pointer;
}

.acrostic-cal-day.has-puzzle {
  background: #3a3428;
  border-color: #6a5a3a;
  color: #f5ecd7;
  font-weight: 700;
}

.acrostic-cal-day.has-puzzle:hover {
  background: #4a4232;
  border-color: #c4a35a;
}

.acrostic-cal-day.locked-puzzle {
  background: #2e2c2a;
  border-color: #4a453e;
  color: #8a8276;
  font-weight: 600;
  opacity: 0.85;
  cursor: default;
}

.acrostic-cal-day.is-today:not(.unavailable) {
  box-shadow: inset 0 0 0 1px #c4a35a88;
}

.acrostic-cal-day.selected.has-puzzle,
.acrostic-cal-day.selected:not(.unavailable):not(.locked-puzzle) {
  background: #c4a35a;
  border-color: #c4a35a;
  color: #1e1c18;
}

.acrostic-cal-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 18px;
  justify-content: center;
  font-size: 0.78rem;
  color: #9a9286;
}

.acrostic-leg-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin-right: 6px;
  vertical-align: middle;
}

.acrostic-leg-dot.has {
  background: #3a3428;
  border: 1px solid #6a5a3a;
}

.acrostic-leg-dot.locked {
  background: #2e2c2a;
  border: 1px solid #4a453e;
}

.acrostic-leg-dot.today {
  box-shadow: inset 0 0 0 1px #c4a35a;
  background: transparent;
}

.acrostic-archive-list {
  width: min(360px, 100%);
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
}

.acrostic-archive-heading {
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #8a8276;
  text-align: left;
  margin-bottom: 2px;
}

.acrostic-archive-empty {
  font-size: 0.85rem;
  color: #8a8276;
  padding: 8px 0;
}

.acrostic-archive-item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #3f3b36;
  border-radius: 6px;
  background: #2a2826;
  color: #e8e0d4;
  cursor: pointer;
  text-align: left;
}

.acrostic-archive-item:hover {
  border-color: #c4a35a88;
  background: #33302c;
}

.acrostic-archive-item.selected {
  border-color: #c4a35a;
  background: #3a3428;
}

.acrostic-archive-title {
  font-size: 0.95rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.acrostic-star {
  color: #c4a35a;
  font-size: 1.05rem;
  flex: 0 0 auto;
  line-height: 1;
}

.acrostic-start-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.acrostic-game-area {
  flex: 1;
  display: none;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  padding: 8px 12px 12px;
  gap: 10px;
}

.acrostic-header-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  color: #cfc7b8;
  font-size: 0.95rem;
}

.acrostic-header-meta .acrostic-title {
  font-weight: 600;
  color: #f0ebe0;
}

.acrostic-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.acrostic-timer {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: #f5ecd7;
  min-width: 3.5rem;
  text-align: center;
}

.acrostic-mini-btn {
  padding: 6px 12px;
  font-size: 0.85rem;
  border: 1px solid #6a6358;
  background: #2a2824;
  color: #e8e4dc;
  border-radius: 4px;
  cursor: pointer;
}

.acrostic-mini-btn:hover {
  background: #3a3630;
}

.acrostic-mini-btn.danger {
  border-color: #8a4a4a;
  color: #e8b8b8;
}

.acrostic-phrase-wrap {
  background: transparent;
  border-radius: 0;
  padding: 10px 8px;
  flex-shrink: 0;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  overflow-x: hidden;
  overflow-y: hidden;
  max-height: none;
}

.acrostic-phrase-grid {
  --phrase-cell: 34px;
  --phrase-letter-gap: 2px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  /* row gap | word gap = exactly one square */
  gap: 8px var(--phrase-cell);
  width: 100%;
  max-width: 920px;
  margin: 0 auto;
  box-sizing: border-box;
  perspective: 700px;
}

.acrostic-phrase-word {
  display: inline-flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: var(--phrase-letter-gap);
}

.acrostic-cell {
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  font-weight: 700;
  font-size: 1rem;
  user-select: none;
}

.acrostic-phrase-cell {
  width: var(--phrase-cell);
  height: var(--phrase-cell);
  flex: 0 0 var(--phrase-cell);
  font-size: 1.05rem;
}

.acrostic-cell-space {
  background: transparent;
  border: none;
}

.acrostic-cell-punct {
  background: transparent;
  color: #afa38c;
  font-size: 1.25rem;
  width: auto;
  min-width: 16px;
  flex: 0 0 auto;
  border: none;
}

.acrostic-cell-empty {
  background: #ffffff;
  border: 1px solid #c8c2b4;
  color: #1a1a1a;
  cursor: pointer;
  border-radius: 4px;
}

/* Filled phrase letters — gold */
.acrostic-cell-solved {
  background: #c4a35a;
  color: #1a1a1a;
  border-radius: 4px;
}

.acrostic-cell-wrong {
  background: #3a2a2a;
  border: 1px solid #6a4545;
  color: #e8b8b8;
  border-radius: 4px;
}

.acrostic-cell-num {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  color: #555555;
  line-height: 1;
  pointer-events: none;
}

.acrostic-phrase-grid .acrostic-cell-num {
  font-size: 0.88rem;
  font-weight: 700;
  color: #555555;
}

.acrostic-hilite {
  outline: 2px solid #ff2d2d !important;
  outline-offset: -1px;
  box-shadow: 0 0 0 1px #ff2d2d inset;
  z-index: 2;
}

.acrostic-cell.acrostic-flip,
.acrostic-clue-cell.acrostic-flip {
  animation: acrostic-tile-flip 0.38s ease both;
  animation-delay: var(--flip-delay, 0ms);
  transform-origin: center center;
  backface-visibility: hidden;
}

@keyframes acrostic-tile-flip {
  0% {
    transform: rotateY(85deg) scale(0.92);
    opacity: 0.35;
  }
  55% {
    transform: rotateY(-12deg) scale(1.03);
    opacity: 1;
  }
  100% {
    transform: rotateY(0deg) scale(1);
    opacity: 1;
  }
}

.acrostic-entry-wrap {
  flex-shrink: 0;
  max-width: 600px;
  width: 100%;
  margin: 0 auto;
  order: 10; /* keep above keyboard when keyboard is appended */
}

.acrostic-answer-entry {
  width: 100%;
  box-sizing: border-box;
  padding: 12px 14px;
  font-size: 1.05rem;
  border: 2px solid #4a463e;
  border-radius: 6px;
  background: #292826;
  color: #e0dde6;
  text-align: center;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  caret-color: transparent;
  cursor: default;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}

.acrostic-answer-entry::placeholder {
  color: #7a7468;
}

.acrostic-answer-entry:focus {
  outline: none;
  border-color: #c4a35a;
}

.acrostic-answer-entry.acrostic-wiggle {
  animation: acrostic-wiggle 0.4s ease;
}

@keyframes acrostic-wiggle {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

.acrostic-clue-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  -webkit-transform: translate3d(0, 0, 0);
  transform: translate3d(0, 0, 0);
  position: relative;
  z-index: 1;
  touch-action: pan-y;
  overscroll-behavior: contain;
  border-radius: 8px;
  background: #222222;
  padding-bottom: 8px;
  margin-bottom: 0;
  border: 1px solid #333;
  --clue-cell: 30px;
  --clue-gap: 4px;
}

.acrostic-game-area.keyboard-host {
  padding-bottom: 0;
}

/* Desktop: hint left of center; first letters form vertical spine at center */
.acrostic-clue-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: start;
  column-gap: 6px;
  padding: 14px 16px;
}

.acrostic-clue-row.clue-even {
  background: #222222;
}

.acrostic-clue-row.clue-odd {
  background: #292826;
}

.acrostic-clue-hint {
  grid-column: 1;
  min-width: 0;
  color: #ffe69f;
  font-size: 0.98rem;
  line-height: 1.35;
  text-align: right;
  padding-right: 6px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

.acrostic-clue-answer-group {
  grid-column: 2 / 4;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  justify-self: start;
  gap: 0;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.acrostic-clue-spine {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  flex: 0 0 auto;
  padding-top: 0;
}

.acrostic-clue-rest {
  display: flex;
  flex-wrap: wrap;
  gap: var(--clue-gap);
  justify-content: flex-start;
  align-items: flex-start;
  align-content: flex-start;
  min-width: 0;
  flex: 1 1 auto;
}

.acrostic-clue-cell,
.acrostic-cell.acrostic-clue-cell {
  width: var(--clue-cell);
  height: var(--clue-cell);
  flex: 0 0 var(--clue-cell);
  font-size: calc(var(--clue-cell) * 0.42);
  border-radius: 4px;
  box-sizing: border-box;
}

.acrostic-clue-spine .acrostic-clue-cell {
  margin-right: var(--clue-gap);
}

/* Word break inside a clue answer (e.g. NORTH Korea) */
.acrostic-clue-spacer {
  width: var(--clue-cell);
  height: var(--clue-cell);
  flex: 0 0 var(--clue-cell);
  box-sizing: border-box;
  background: transparent;
  border: none;
  pointer-events: none;
}

/* Filled clue letters — dark bg, high-contrast letters */
.acrostic-clue-solved {
  background: #1a1a1a;
  color: #f5ecd7;
}

.acrostic-clue-from-grid {
  background: #1a1a1a;
  border: 1px solid #0f0f0f;
  color: #f5ecd7;
}

/* Gold for first-letter spine — empty AND filled */
.acrostic-clue-cell.acrostic-first-letter.acrostic-cell-empty {
  background: #c4a35a;
  border-color: #a8883e;
}

.acrostic-clue-cell.acrostic-first-letter.acrostic-cell-empty .acrostic-cell-num {
  color: #3a3018;
}

.acrostic-clue-cell.acrostic-first-letter.acrostic-clue-solved,
.acrostic-clue-cell.acrostic-first-letter.acrostic-clue-from-grid {
  background: #c4a35a;
  color: #1a1a1a;
}

.acrostic-first-letter {
  box-shadow: none;
}

.acrostic-round #iosKeyboard.keyboard-active,
.acrostic-round #iosKeyboard.acrostic-keyboard {
  position: relative !important;
  left: auto !important;
  right: auto !important;
  bottom: auto !important;
  transform: none !important;
  width: 100% !important;
  max-width: 600px !important;
  flex: 0 0 auto;
  order: 20;
  margin: 8px auto 0;
  z-index: 1;
  border-radius: 10px;
  align-self: center;
}

/* Acrostic: letters + backspace only — no space / enter / 123 / math row */
.acrostic-round #iosKeyboard .bottom-row {
  display: none !important;
}

.acrostic-pause-overlay {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  z-index: 10;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 16px;
  color: #f5f0e6;
}

.acrostic-results {
  flex: 1;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  color: #e8e4dc;
  gap: 12px;
}

.acrostic-results h2 {
  margin: 0;
  font-size: 1.8rem;
  color: #f5ecd7;
}

.acrostic-results-stats {
  display: flex;
  gap: 28px;
  margin: 8px 0;
}

.acrostic-results-stats .stat-value {
  font-size: 1.4rem;
  font-weight: 700;
  color: #f0d24a;
}

.acrostic-results-stats .stat-label {
  font-size: 0.8rem;
  color: #a8a090;
}

.acrostic-results-phrase {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: #c4a35a;
  margin: 0;
}

.acrostic-results-block {
  width: min(520px, 100%);
  text-align: center;
}

.acrostic-results-label {
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #8a8276;
  margin-bottom: 6px;
}

.acrostic-results-quote {
  font-size: 1rem;
  line-height: 1.45;
  color: #f5ecd7;
  font-weight: 600;
}

.acrostic-results-buttons {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.acrostic-viewing-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  margin-bottom: 4px;
  border: 1px solid #4a453e;
  border-radius: 6px;
  background: #2a2826;
  color: #cfc7b8;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.mode-button.acrostic-mode {
  background: #292826;
  border: 2px solid #c4a35a;
  color: #f5ecd7;
}

/* Mobile breakpoint matches app (768px) — left-aligned clues for readability */
@media (max-width: 768px) {
  .acrostic-phrase-grid {
    --phrase-cell: 28px;
    --phrase-letter-gap: 1px;
    gap: 6px var(--phrase-cell);
    max-width: 100%;
  }

  .acrostic-phrase-grid .acrostic-cell-num {
    font-size: 0.72rem;
  }

  .acrostic-phrase-wrap {
    padding: 6px 4px;
  }

  .acrostic-clue-list {
    --clue-cell: 28px;
  }

  .acrostic-game-area {
    padding: 6px 4px 8px;
    gap: 8px;
  }

  .acrostic-clue-row {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 10px 8px;
  }

  .acrostic-clue-hint {
    width: 100%;
    text-align: left;
    padding-right: 0;
    font-size: 0.88rem;
  }

  .acrostic-clue-answer-group {
    width: 100%;
    max-width: 100%;
    justify-content: flex-start;
    align-items: flex-start;
    flex-wrap: nowrap;
  }

  .acrostic-clue-rest {
    flex: 1 1 auto;
    width: auto;
    min-width: 0;
    flex-wrap: wrap;
    row-gap: var(--clue-gap);
  }

  .acrostic-clue-cell .acrostic-cell-num {
    font-size: calc(var(--clue-cell) * 0.38);
  }

  .acrostic-entry-wrap {
    max-width: 100%;
  }

  .acrostic-round #iosKeyboard.keyboard-active,
  .acrostic-round #iosKeyboard.acrostic-keyboard {
    max-width: 100% !important;
  }
}

/* Extra-narrow phones (~400px CSS width) */
@media (max-width: 430px) {
  .acrostic-game-area {
    padding: 4px 2px 6px;
    gap: 6px;
  }

  .acrostic-phrase-grid {
    --phrase-cell: 24px;
    --phrase-letter-gap: 1px;
    gap: 5px var(--phrase-cell);
  }

  .acrostic-phrase-grid .acrostic-cell-num {
    font-size: 0.62rem;
  }

  .acrostic-phrase-wrap {
    padding: 4px 2px;
  }

  .acrostic-clue-list {
    --clue-cell: 24px;
  }

  .acrostic-clue-row {
    padding: 8px 6px;
  }
}
