/* existence — typography, layout, atmosphere */

@import url('https://fonts.googleapis.com/css2?family=Source+Serif+4:ital,wght@0,300;0,400;1,300;1,400&display=swap');

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

html {
  font-size: 18px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  background: #1a1a1a;
  color: #c8c0b8;
  font-family: 'Source Serif 4', 'Georgia', serif;
  font-weight: 300;
  line-height: 1.7;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 0;
}

#game {
  max-width: 36rem;
  width: 100%;
  padding: 3rem 1.5rem;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

#awareness {
  text-align: right;
  font-size: 0.8rem;
  min-height: 1.4em;
  display: flex;
  justify-content: flex-end;
  gap: 1.5em;
}

#awareness span {
  transition: opacity 0.3s ease, color 0.3s ease;
  cursor: pointer;
}

#awareness.hidden {
  display: none;
}

#afk-indicator {
  margin-right: auto;
  opacity: 0.2;
}

#afk-indicator.detection-off {
  opacity: 0.4;
}

#afk-indicator.hidden {
  display: none;
}

#text-area {
  flex: 1;
  margin-bottom: 2rem;
}

#passage {
  opacity: 0;
  transition: opacity 0.6s ease;
}

#passage.visible {
  opacity: 1;
}

#passage p {
  margin-bottom: 1em;
}

#event-text {
  margin-top: 1.2em;
  opacity: 0;
  transition: opacity 0.5s ease;
  color: #a09890;
  font-style: italic;
}

#event-text.visible {
  opacity: 1;
}

/* Inner voice — typographic intensity as NT readout */

#event-text p.inner-voice--uneasy {
  letter-spacing: 0.015em;
  color: #b0a898;
}

#event-text p.inner-voice--prominent {
  color: #c0b8b0;
  font-weight: 400;
}

#event-text p.inner-voice--tremor {
  color: #c8c0b8;
  font-weight: 400;
  animation: inner-voice-shake 0.35s ease-in-out infinite;
}

@keyframes inner-voice-shake {
  0%, 100% { transform: translateX(0); }
  25%       { transform: translateX(-1.5px); }
  75%       { transform: translateX(1.5px); }
}

@media (prefers-reduced-motion: reduce) {
  #event-text p.inner-voice--tremor {
    animation: none;
    color: #e0d8d0;
    font-weight: 400;
  }
}

/* Actions — feel like part of the text, not a menu */

#actions {
  padding-top: 1.5rem;
  border-top: 1px solid #2a2826;
  opacity: 0;
  transition: opacity 0.4s ease 0.3s;
}

#actions.visible {
  opacity: 1;
}

.action {
  display: block;
  background: none;
  border: none;
  color: #8a8078;
  font-family: 'Source Serif 4', 'Georgia', serif;
  font-weight: 300;
  font-size: 1rem;
  line-height: 1.7;
  padding: 0.3em 0;
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: color 0.2s ease;
}

.action:hover {
  color: #d4ccc4;
}

.action:active {
  color: #e8e0d8;
}

.action::before {
  content: '';
  display: inline;
}

/* Movement — separate from actions, quieter */

#movement {
  margin-top: 1rem;
  padding-top: 0.8rem;
  opacity: 0;
  transition: opacity 0.4s ease 0.5s;
}

#movement.visible {
  opacity: 1;
}

.movement-link {
  display: inline-block;
  background: none;
  border: none;
  color: #605850;
  font-family: 'Source Serif 4', 'Georgia', serif;
  font-weight: 300;
  font-size: 0.9rem;
  line-height: 1.7;
  padding: 0.15em 0;
  margin-right: 1.5em;
  cursor: pointer;
  transition: color 0.2s ease;
}

.movement-link:hover {
  color: #a09890;
}

.movement-link:active {
  color: #c8c0b8;
}

/* Responsive */

@media (max-width: 600px) {
  html {
    font-size: 16px;
  }

  #game {
    padding: 2rem 1.25rem;
  }
}

/* Scrollbar — minimal */

::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: #1a1a1a;
}

::-webkit-scrollbar-thumb {
  background: #333;
  border-radius: 2px;
}

/* Name inputs — chargen custom name fields */

.name-input-wrapper {
  margin-bottom: 0.5em;
  display: flex;
  align-items: baseline;
  gap: 0.5em;
}

.name-input {
  background: transparent;
  border: none;
  border-bottom: 1px solid #3a3530;
  color: #c8c0b8;
  font-family: 'Source Serif 4', 'Georgia', serif;
  font-weight: 300;
  font-size: 1rem;
  line-height: 1.7;
  padding: 0.2em 0;
  width: 100%;
  max-width: 14em;
  outline: none;
  transition: border-color 0.2s ease;
}

.name-input:focus {
  border-bottom-color: #8a8078;
}

.name-input::placeholder {
  color: #4a4540;
}

/* Chargen — single-page option buttons */

.chargen-group {
  margin-bottom: 1.5em;
}

.chargen-option {
  display: block;
  background: none;
  border: none;
  color: #605850;
  font-family: 'Source Serif 4', 'Georgia', serif;
  font-weight: 300;
  font-size: 1rem;
  line-height: 1.7;
  padding: 0.15em 0;
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: color 0.2s ease;
}

.chargen-option:hover {
  color: #a09890;
}

.chargen-option.selected {
  color: #c8c0b8;
}

/* Chargen — custom dropdown (looks like prose, expands on click) */

.chargen-dropdown {
  display: inline;
  position: relative;
}

.chargen-dropdown-trigger {
  border-bottom: 1px solid #3a3530;
  padding-bottom: 1px;
  cursor: pointer;
  transition: border-color 0.3s ease, color 0.3s ease;
}

.chargen-dropdown-trigger:hover {
  border-bottom-color: #504840;
}

.chargen-dropdown-options {
  display: none;
  padding: 0.3em 0;
  overflow-wrap: break-word;
}

.chargen-dropdown-options.open {
  display: block;
  position: sticky;
  bottom: 0;
  right: 0;
}

/* Name re-roll buttons */

.name-reroll {
  background: none;
  border: none;
  color: #4a4540;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  transition: color 0.2s ease;
}

.name-reroll:hover {
  color: #8a8078;
}

/* Age input — inline number in prose */

.age-input {
  background: transparent;
  border: none;
  border-bottom: 1px solid #3a3530;
  color: #c8c0b8;
  font-family: 'Source Serif 4', 'Georgia', serif;
  font-weight: 300;
  font-size: 1rem;
  line-height: 1.7;
  padding: 0.2em 0;
  width: 2.5em;
  text-align: center;
  outline: none;
  transition: border-color 0.2s ease;
}

.age-input:focus {
  border-bottom-color: #8a8078;
}

/* Editable name — inline contenteditable, looks like prose */

.editable-name {
  border-bottom: 1px solid #3a3530;
  padding-bottom: 1px;
  outline: none;
  transition: border-color 0.3s ease, color 0.3s ease;
  cursor: text;
}

.editable-name:hover {
  border-bottom-color: #504840;
}

.editable-name:focus {
  border-bottom-color: #8a8078;
  color: #e0d8d0;
}

/* Step away — quiet, persistent exit to threshold */

#step-away {
  margin-top: 1.5rem;
  padding-top: 0.5rem;
  color: #605850;
  font-size: 0.9rem;
  cursor: pointer;
  opacity: 0.5;
  transition: opacity 0.4s ease, color 0.3s ease;
  letter-spacing: 0.15em;
}

#step-away.arriving {
  animation: step-away-arrive 2s ease-out;
}

@keyframes step-away-arrive {
  0%   { opacity: 0; }
  30%  { opacity: 0.7; }
  100% { opacity: 0.5; }
}

#step-away:hover {
  opacity: 0.8;
  color: #8a8078;
}

#step-away.hidden {
  display: none;
}

/* Look back — quiet replay entry, matches step-away */

#look-back {
  padding-top: 0.3rem;
  color: #605850;
  font-size: 0.9rem;
  cursor: pointer;
  opacity: 0.5;
  transition: opacity 0.4s ease, color 0.3s ease;
  letter-spacing: 0.15em;
}

#look-back.arriving {
  animation: step-away-arrive 2s ease-out;
}

#look-back:hover {
  opacity: 0.8;
  color: #8a8078;
}

#look-back.hidden {
  display: none;
}

/* Replay controls — scrubber + heatmap */

#replay-controls {
  margin-top: 1.5rem;
  padding-top: 1rem;
}

#replay-controls.hidden {
  display: none;
}

#replay-scrubber-track {
  position: relative;
  width: 100%;
  height: 18px;
  display: flex;
  align-items: center;
}

#replay-heatmap {
  position: absolute;
  top: 5px;
  left: 0;
  width: 100%;
  height: 8px;
  image-rendering: pixelated;
  pointer-events: none;
  border-radius: 1px;
}

#replay-scrubber {
  position: relative;
  width: 100%;
  height: 18px;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  cursor: pointer;
  z-index: 1;
}

#replay-scrubber::-webkit-slider-runnable-track {
  height: 8px;
  background: transparent;
  border-radius: 1px;
}

#replay-scrubber::-moz-range-track {
  height: 8px;
  background: transparent;
  border-radius: 1px;
  border: none;
}

#replay-scrubber::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 3px;
  height: 14px;
  background: #8a8078;
  border: none;
  border-radius: 1px;
  margin-top: -3px;
  cursor: pointer;
}

#replay-scrubber::-moz-range-thumb {
  width: 3px;
  height: 14px;
  background: #8a8078;
  border: none;
  border-radius: 1px;
  cursor: pointer;
}

#replay-nav {
  display: flex;
  align-items: center;
  gap: 0.8em;
  margin-top: 0.5rem;
}

.replay-btn {
  background: none;
  border: none;
  color: #605850;
  font-family: 'Source Serif 4', 'Georgia', serif;
  font-weight: 300;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0.2em 0.4em;
  transition: color 0.2s ease;
}

.replay-btn:hover {
  color: #a09890;
}

.replay-btn-back {
  margin-left: auto;
}

#replay-scene-label {
  color: #605850;
  font-size: 0.8rem;
  font-style: italic;
}

/* Selection */

::selection {
  background: #3a3530;
  color: #e0d8d0;
}

/* ============================================================
   Phone overlay
   ============================================================ */

#phone {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 260px;
  height: 520px;
  border-radius: 36px;
  border: 1.5px solid #2a2826;
  background: #0a0a0a;
  box-shadow: 0 24px 64px rgba(0,0,0,.85), inset 0 0 0 1px #1c1a18;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 100;
  font-family: -apple-system, 'SF Pro Text', 'Helvetica Neue', sans-serif;
  font-size: 14px;
  color: #d0c8c0;
}

#phone[hidden] {
  display: none;
}

/* Dim background when phone is open */
body.phone-open #game {
  filter: brightness(0.35);
  pointer-events: none;
}

/* Status bar */
.phone-status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 18px 4px;
  font-size: 11px;
  color: #7a726a;
  flex-shrink: 0;
  background: none;
  border: none;
  width: 100%;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
}

.phone-battery-pct--low {
  color: #c05030;
}

.phone-silent-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #c07850;
  vertical-align: middle;
  margin: 0 2px;
}

/* Notifications / quick settings shade */
.phone-notifications {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

.phone-notif-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 14px 18px 12px;
}

.phone-notif-time {
  font-size: 28px;
  font-weight: 200;
  color: #c8c0b8;
  letter-spacing: -0.5px;
}

.phone-notif-close {
  background: none;
  border: none;
  color: #5a5250;
  font-size: 16px;
  cursor: pointer;
  padding: 4px 6px;
  font-family: inherit;
  line-height: 1;
}

.phone-notif-close:hover {
  color: #908880;
}

.phone-quick-settings {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 4px 18px 20px;
}

.phone-quick-tile {
  background: #2a2825;
  border: 1px solid #3a3530;
  border-radius: 10px;
  color: #908880;
  font-family: inherit;
  font-size: 12px;
  padding: 12px 16px;
  cursor: pointer;
  min-width: 80px;
  text-align: center;
  transition: background 0.15s ease, color 0.15s ease;
}

.phone-quick-tile--silent-on {
  background: #3a2820;
  border-color: #c07850;
  color: #c07850;
}

.phone-quick-tile:hover {
  background: #383530;
  color: #c8c0b8;
}

/* Home screen */
.phone-home-time {
  font-size: 52px;
  font-weight: 200;
  text-align: center;
  letter-spacing: -1px;
  margin: 10px 0 4px;
  color: #d8d0c8;
  flex-shrink: 0;
}

.phone-home-date {
  text-align: center;
  font-size: 13px;
  color: #908880;
  margin-bottom: 28px;
  flex-shrink: 0;
}

.phone-apps {
  flex: 1;
  padding: 0 20px;
}

.phone-app {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.5em;
  background: #181614;
  border: 1px solid #2a2826;
  border-radius: 14px;
  color: #b0a898;
  font-family: inherit;
  font-size: 14px;
  padding: 12px 16px;
  width: 100%;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s ease, color 0.15s ease;
}

.phone-app:hover {
  background: #1e1c1a;
  color: #c8c0b8;
}

.phone-app-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #b03020;
  color: #e8e0d8;
  border-radius: 10px;
  font-size: 11px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  margin-left: auto;
}

/* Home bar (tap = put away) */
.phone-home-bar {
  display: block;
  width: 100%;
  background: none;
  border: none;
  border-top: 1px solid #1e1c1a;
  color: #3a3530;
  font-size: 18px;
  padding: 10px 0 12px;
  text-align: center;
  cursor: pointer;
  letter-spacing: 4px;
  flex-shrink: 0;
  transition: color 0.2s ease;
}

.phone-home-bar:hover {
  color: #605850;
}

/* Navigation header (messages list + thread) */
.phone-nav-header {
  display: flex;
  align-items: center;
  padding: 8px 14px 8px;
  border-bottom: 1px solid #1e1c1a;
  flex-shrink: 0;
}

.phone-nav-back {
  background: none;
  border: none;
  color: #7a726a;
  font-size: 24px;
  cursor: pointer;
  padding: 0 8px 0 0;
  line-height: 1;
  transition: color 0.15s ease;
}

.phone-nav-back:hover {
  color: #b0a898;
}

.phone-nav-title {
  font-size: 15px;
  font-weight: 500;
  color: #c8c0b8;
  letter-spacing: 0.01em;
}

/* Contact list */
.phone-contact-list {
  flex: 1;
  overflow-y: auto;
}

.phone-contact-row {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  align-items: center;
  gap: 0 8px;
  width: 100%;
  background: none;
  border: none;
  border-bottom: 1px solid #161412;
  padding: 10px 16px;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s ease;
}

.phone-contact-row:hover {
  background: #121010;
}

.phone-contact-name {
  grid-column: 1;
  grid-row: 1;
  font-size: 14px;
  color: #c0b8b0;
  font-weight: 400;
}

.phone-contact-preview {
  grid-column: 1;
  grid-row: 2;
  font-size: 12px;
  color: #5a5250;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 190px;
}

.phone-contact-row--unread .phone-contact-name {
  color: #d8d0c8;
}

.phone-contact-row--unread .phone-contact-preview {
  color: #8a8278;
}

.phone-unread-dot {
  grid-column: 2;
  grid-row: 1 / 3;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4a8ccc;
  display: block;
  align-self: center;
}

/* Thread messages */
.phone-thread-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.phone-bubble {
  max-width: 82%;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.phone-bubble--sent {
  align-self: flex-end;
  align-items: flex-end;
}

.phone-bubble--received {
  align-self: flex-start;
  align-items: flex-start;
}

.phone-bubble-sender {
  font-size: 10px;
  color: #4a4540;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.phone-bubble--sent .phone-bubble-sender {
  color: #3a6a90;
}

.phone-bubble-text {
  font-size: 13px;
  line-height: 1.5;
  padding: 7px 10px;
  border-radius: 14px;
  color: #c0b8b0;
  background: #1a1816;
}

.phone-bubble--sent .phone-bubble-text {
  background: #1a2e40;
  color: #a8c0d8;
}

.phone-bubble--unread .phone-bubble-text {
  color: #d8d0c8;
}

/* Compose row */
.phone-compose {
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid #1e1c1a;
  flex-shrink: 0;
}

.phone-compose-btn {
  flex: 1;
  background: #181614;
  border: 1px solid #2a2826;
  border-radius: 10px;
  color: #a09890;
  font-family: inherit;
  font-size: 13px;
  padding: 8px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.phone-compose-btn:hover {
  background: #201e1c;
  color: #c8c0b8;
}

/* Amount input row (help_friend) */
.phone-amount-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
}

.phone-amount-prefix {
  color: #807870;
  font-size: 14px;
  flex-shrink: 0;
}

.phone-amount-input {
  flex: 1;
  min-width: 0;
  background: #181614;
  border: 1px solid #2a2826;
  border-radius: 10px;
  color: #c8c0b8;
  font-family: inherit;
  font-size: 13px;
  padding: 8px 10px;
  appearance: textfield;
}

.phone-amount-input::-webkit-inner-spin-button,
.phone-amount-input::-webkit-outer-spin-button {
  appearance: none;
}

.phone-amount-input::placeholder {
  color: #504848;
}

.phone-amount-input:focus {
  outline: none;
  border-color: #3a3634;
}

.phone-amount-send {
  flex: 0 0 auto;
  padding: 8px 14px;
}

/* Empty state */
.phone-empty {
  color: #4a4540;
  font-size: 13px;
  text-align: center;
  padding: 20px;
}

/* Cracked screen overlay — cosmetic, derived from economic_origin at chargen */
#phone.phone--cracked {
  position: relative;
}

#phone.phone--cracked::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 200;
  border-radius: 36px;
  overflow: hidden;
  background:
    /* Primary crack: lower-left corner radiating up-right */
    linear-gradient(34deg,
      transparent 18%,
      rgba(255,255,255,0.18) 18.4%,
      rgba(255,255,255,0.07) 18.9%,
      transparent 19.4%
    ),
    /* Branch off primary: angles up more steeply */
    linear-gradient(58deg,
      transparent 32%,
      rgba(255,255,255,0.13) 32.3%,
      rgba(255,255,255,0.05) 32.7%,
      transparent 33.1%
    ),
    /* Short hairline, different origin point */
    linear-gradient(21deg,
      transparent 11%,
      rgba(255,255,255,0.10) 11.3%,
      rgba(255,255,255,0.04) 11.6%,
      transparent 12.0%
    );
}

/* Scrollbar inside phone */
#phone ::-webkit-scrollbar {
  width: 2px;
}

#phone ::-webkit-scrollbar-track {
  background: transparent;
}

#phone ::-webkit-scrollbar-thumb {
  background: #2a2826;
  border-radius: 1px;
}
