/* LIFE — in-game screen (matches the phone and desktop mockups)
 *
 * Phone / tablet portrait: one column filling the screen
 *   header · info bar · picture · story · input · Continue · 4 tiles
 * Desktop / landscape: picture with the info cards beside it,
 *   story underneath, input + Continue + actions along the bottom.
 */

#topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: calc(60px + var(--safe-top));
  padding:
    var(--safe-top)
    max(16px, calc((100vw - 1100px) / 2), var(--safe-right))
    0
    max(16px, calc((100vw - 1100px) / 2), var(--safe-left));
  background: rgba(9, 14, 21, 0.82);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

#topbar .brand {
  min-height: 40px;
  padding: 4px 0;
  border: 0;
  box-shadow: none;
  font-family: var(--serif-display);
  font-size: 28px;
  font-weight: 400;
  letter-spacing: 0.4em;
  background: linear-gradient(180deg, #fffaf0, #d7b77c);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* ---------- Palette for the game screen ---------- */

#game {
  --g-bg: #18212c;
  --g-panel-top: #1b2531;
  --g-panel-bottom: #111923;
  --g-gold: #d9b77c;
  --g-gold-soft: rgba(217, 183, 124, 0.55);
  --g-gold-line: rgba(217, 183, 124, 0.38);
  --g-label: #e8d3a8;
  --g-value: #f6efe2;
  --g-faint: #8d98a5;
  --g-red: #e0584c;
}

body[data-screen="game"] {
  background:
    radial-gradient(ellipse at 50% 0%, #2a3644 0, transparent 60%),
    #151c25;
}

/* ---------- Layout ---------- */

#game {
  display: grid;
  gap: 10px;
  height: 100vh;
  height: 100dvh;
  max-width: 760px;
  margin: 0 auto;
  padding:
    calc(10px + var(--safe-top))
    max(12px, var(--safe-right))
    calc(10px + var(--safe-bottom))
    max(12px, var(--safe-left));
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows:
    auto
    auto
    minmax(150px, 1.45fr)
    minmax(120px, 1fr)
    auto
    auto
    auto;
  grid-template-areas:
    "head"
    "stats"
    "frame"
    "story"
    "compose"
    "cont"
    "actions";
}

#game > .g-head { grid-area: head; }
#game > .status { grid-area: stats; }
#game > .frame { grid-area: frame; }
#game > .story-panel { grid-area: story; }
#game > .compose { grid-area: compose; }
#game > .continue-btn { grid-area: cont; }
#game > .g-actions { grid-area: actions; }

#game .desk { display: none !important; }

/* ---------- Shared panel ---------- */

#game .panel {
  background: linear-gradient(180deg, var(--g-panel-top), var(--g-panel-bottom));
  border: 1.5px solid var(--g-gold-soft);
  border-radius: 16px;
  box-shadow:
    inset 0 1px 0 rgba(255, 240, 210, 0.06),
    0 10px 28px rgba(0, 0, 0, 0.35);
}

#game .ic {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
}

#game button {
  -webkit-user-select: none;
  user-select: none;
}

/* ---------- Header ---------- */

.g-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 !important;
  background: none !important;
  border: 0 !important;
  box-shadow: none !important;
}

.g-brand {
  flex: 1;
  min-width: 0;
  padding: 10px 18px 9px;
  background: linear-gradient(180deg, var(--g-panel-top), var(--g-panel-bottom));
  border: 1.5px solid var(--g-gold-line);
  border-radius: 16px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
}

.g-mark {
  display: flex;
  align-items: center;
  gap: 8px;
}

.g-life {
  font-family: var(--serif-display);
  font-size: 46px;
  font-weight: 600;
  line-height: 0.95;
  letter-spacing: 0.14em;
  background: linear-gradient(180deg, #fbefd6 5%, #d9b77c 60%, #b8925a 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.g-spark {
  width: 18px;
  height: 18px;
  color: var(--g-gold);
  flex-shrink: 0;
}

.g-rule {
  flex: 1;
  max-width: 160px;
  height: 1px;
  background: linear-gradient(90deg, var(--g-gold), transparent);
}

.g-tag {
  margin-top: 6px;
  font-family: var(--serif-display);
  font-size: clamp(9px, 2.6vw, 12px);
  font-weight: 600;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: #cfd4da;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.g-top {
  display: flex;
  gap: 8px;
}

.g-btn {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 0;
  padding: 9px 14px;
  border-radius: 12px;
  border: 1.5px solid var(--g-gold-line);
  background: linear-gradient(180deg, #18212c, #0f161f);
  font-family: var(--serif-display);
  font-size: 17px;
  color: var(--g-value);
  letter-spacing: 0.02em;
}

.g-btn .ic {
  color: var(--g-gold);
}

/* Phone: Menu is a square button with the label under the icon */
.g-menu {
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  width: 78px;
  height: 78px;
  padding: 6px;
  font-size: 16px;
}

.g-menu .ic {
  width: 30px;
  height: 30px;
  color: var(--g-value);
}

/* ---------- Info bar: Name · Age · Location · Date ---------- */

.status {
  display: grid;
  grid-template-columns: 1.05fr 0.75fr 1.15fr 1.05fr;
  padding: 10px 4px;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 0;
  padding: 0 6px;
  text-align: center;
  border-left: 1px solid var(--g-gold-line);
}

.stat:first-child {
  border-left: 0;
}

.stat-ic {
  width: 30px;
  height: 30px;
  color: var(--g-gold);
  flex-shrink: 0;
}

.stat-text {
  min-width: 0;
  width: 100%;
}

.stat-text span {
  display: block;
  font-family: var(--serif-display);
  font-size: 15px;
  font-weight: 600;
  color: var(--g-label);
}

.stat-text strong {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-family: var(--serif-text);
  font-size: 14px;
  font-weight: 400;
  line-height: 1.25;
  color: var(--g-value);
  overflow-wrap: anywhere;
}

/* ---------- Picture ---------- */

.frame {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  border-color: rgba(217, 183, 124, 0.75) !important;
  background:
    radial-gradient(ellipse at 40% 20%, #3a4757 0, transparent 70%),
    linear-gradient(180deg, #2b3542, #171f29) !important;
}

/* Blurred copy of the picture fills the frame behind it, so square
   pictures look cinematic instead of sitting between bars. */
.frame-backdrop {
  position: absolute;
  inset: -40px;
  background: center / cover no-repeat;
  filter: blur(34px) brightness(0.55) saturate(1.15);
  transform: scale(1.1);
}

.frame img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  animation: develop 1.1s ease both;
}

@keyframes develop {
  from { opacity: 0; filter: brightness(1.4) blur(6px); }
  to { opacity: 1; filter: none; }
}

.frame-empty {
  position: relative;
  color: var(--g-faint);
  text-align: center;
  padding: 30px;
  font-family: var(--serif-display);
  font-style: italic;
  font-size: 21px;
}

.frame.loading::after {
  content: "Developing your photograph...";
  position: absolute;
  inset: auto 0 0 0;
  padding: 40px 90px 22px 16px;
  text-align: left;
  font-family: var(--serif-display);
  font-style: italic;
  font-size: 19px;
  color: var(--g-label);
  background: linear-gradient(transparent, rgba(5, 8, 12, 0.8));
  animation: breathe 2.4s ease-in-out infinite;
}

.frame-tools {
  position: absolute;
  right: 14px;
  bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 2;
}

.pic-count {
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(8, 12, 18, 0.7);
  border: 1px solid var(--g-gold-line);
  font-family: var(--serif-display);
  font-size: 14px;
  color: var(--g-label);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.round-btn {
  display: grid;
  place-items: center;
  width: 60px;
  height: 60px;
  min-height: 0;
  padding: 0;
  border-radius: 50%;
  border: 2px solid var(--g-gold);
  background: rgba(10, 14, 20, 0.72);
  color: var(--g-label);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.round-btn .ic {
  width: 28px !important;
  height: 28px !important;
}

/* ---------- Story ---------- */

.story-panel {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 30px;
  min-height: 0;
  overflow: hidden;
}

.story {
  min-height: 0;
  overflow-y: auto;
  padding: 16px 6px 16px 20px;
  font-family: var(--serif-text);
  font-size: var(--story-size);
  line-height: 1.7;
  color: #f1ebdf;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  scrollbar-width: none;
  outline: none;
  -webkit-overflow-scrolling: touch;
}

.story::-webkit-scrollbar {
  display: none;
}

.story.typing::after {
  content: "▍";
  color: var(--g-gold);
  animation: blink 0.8s steps(2) infinite;
}

@keyframes blink {
  50% { opacity: 0; }
}

.rail {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  justify-items: center;
  padding: 8px 6px 8px 0;
  transition: opacity 0.3s;
}

.rail.idle {
  opacity: 0.35;
}

.rail-btn {
  width: 24px;
  height: 22px;
  min-height: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--g-gold);
  box-shadow: none !important;
}

.rail-btn .ic {
  width: 20px !important;
  height: 20px !important;
}

.rail-track {
  position: relative;
  width: 8px;
  margin: 6px 0;
  border-radius: 999px;
  background: rgba(217, 183, 124, 0.12);
  cursor: pointer;
  touch-action: none;
}

.rail-thumb {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #a98552, #f0d7a6 50%, #a98552);
  box-shadow: 0 0 10px rgba(240, 215, 166, 0.25);
}

/* ---------- Input ---------- */

.compose {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px 8px 16px;
  border-color: rgba(217, 183, 124, 0.7) !important;
}

.quill {
  width: 34px;
  height: 34px;
  color: #b9bfc6;
  flex-shrink: 0;
}

.compose-rule {
  align-self: stretch;
  width: 1px;
  margin: 6px 0;
  background: var(--g-gold-line);
}

.compose textarea {
  flex: 1;
  min-height: 46px;
  max-height: 140px;
  padding: 11px 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  resize: none;
  font-family: var(--serif-text);
  font-size: 20px;
  line-height: 1.3;
}

.compose textarea:focus {
  box-shadow: none;
}

.compose textarea::placeholder {
  color: #8a929b;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  min-height: 0;
  padding: 0;
  border-radius: 10px;
  border: 1px solid transparent;
  background: none;
  color: var(--g-label);
}

.icon-btn.on {
  border-color: var(--g-gold);
  background: rgba(217, 183, 124, 0.16);
  color: #fff3d8;
  box-shadow: 0 0 16px rgba(217, 183, 124, 0.3);
}

/* ---------- Continue ---------- */

.continue-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  min-height: 62px;
  border-radius: 14px;
  background: linear-gradient(180deg, #f6dfb3 0%, #e1bf86 55%, #c99f62 100%) !important;
  border: 1.5px solid #f7e4bd !important;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.5),
    0 10px 26px rgba(201, 159, 98, 0.22);
  color: #17120b;
  font-family: var(--serif-display);
  font-size: 30px;
  font-weight: 600;
}

.continue-btn .ic {
  width: 30px !important;
  height: 30px !important;
}

/* ---------- Action tiles ---------- */

.g-actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 84px;
  padding: 8px 6px;
  border-radius: 14px;
  border: 1.5px solid var(--g-gold-line);
  background: linear-gradient(180deg, #19222d, #0f161f);
  color: var(--g-value);
  font-family: var(--serif-display);
  font-size: 17px;
  line-height: 1.1;
  text-align: center;
}

.tile .ic {
  width: 32px !important;
  height: 32px !important;
  color: var(--g-gold);
}

.tile-end .ic {
  color: var(--g-red);
}

/* Ended life: input is closed */
body.life-ended .compose,
body.life-ended .continue-btn {
  opacity: 0.5;
}

/* ---------- Small and short phones (iPhone SE, mini) ---------- */

@media (max-width: 380px), (max-height: 740px) {
  #game {
    gap: 8px;
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    grid-template-rows: auto auto 210px 170px auto auto auto;
  }

  .g-brand {
    padding: 8px 14px 7px;
  }

  .g-life {
    font-size: 34px;
  }

  .g-tag {
    margin-top: 4px;
    font-size: 9px;
    letter-spacing: 0.2em;
  }

  .g-menu {
    width: 62px;
    height: 62px;
    font-size: 14px;
  }

  .g-menu .ic {
    width: 24px;
    height: 24px;
  }

  .status {
    padding: 8px 2px;
  }

  .stat-ic {
    width: 22px;
    height: 22px;
  }

  .stat-text span {
    font-size: 13px;
  }

  .stat-text strong {
    font-size: 13px;
  }

  .compose textarea {
    font-size: 18px;
    min-height: 40px;
    padding: 8px 0;
  }

  .quill {
    width: 28px;
    height: 28px;
  }

  .continue-btn {
    min-height: 52px;
    font-size: 26px;
  }

  .tile {
    min-height: 66px;
    gap: 4px;
    font-size: 14px;
  }

  .tile .ic {
    width: 24px !important;
    height: 24px !important;
  }

  .round-btn {
    width: 50px;
    height: 50px;
  }
}

/* ---------- Desktop and landscape tablets ---------- */

@media (min-width: 900px) and (min-aspect-ratio: 5/4) {
  #game {
    max-width: 1680px;
    gap: 12px;
    padding:
      calc(14px + var(--safe-top))
      max(22px, var(--safe-right))
      calc(14px + var(--safe-bottom))
      max(22px, var(--safe-left));
    grid-template-columns: minmax(0, 1fr) 190px minmax(300px, 340px);
    grid-template-rows: auto minmax(0, 1.55fr) minmax(110px, 1fr) auto;
    grid-template-areas:
      "head head head"
      "frame frame stats"
      "story story story"
      "compose cont actions";
  }

  #game .desk { display: flex !important; }
  #game span.desk { display: inline !important; }
  #game .phone { display: none !important; }

  /* Header becomes one bar */
  .g-head {
    padding: 8px 10px 8px 22px !important;
    background: linear-gradient(180deg, var(--g-panel-top), var(--g-panel-bottom)) !important;
    border: 1.5px solid var(--g-gold-line) !important;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35) !important;
  }

  .g-brand {
    display: flex;
    align-items: center;
    gap: 22px;
    padding: 0;
    background: none;
    border: 0;
    box-shadow: none;
  }

  .g-life {
    font-size: 44px;
  }

  .g-rule {
    width: 120px;
    flex: none;
  }

  .g-tag {
    margin: 0;
    font-size: 12px;
  }

  .g-menu {
    flex-direction: row;
    width: auto;
    height: auto;
    padding: 9px 14px;
    gap: 9px;
    font-size: 17px;
  }

  .g-menu .ic {
    width: 24px;
    height: 24px;
    color: var(--g-gold);
  }

  /* Info cards stacked beside the picture */
  .status {
    grid-template-columns: 1fr;
    grid-template-rows: repeat(4, minmax(0, 1fr));
    gap: 10px;
    padding: 12px;
    min-height: 0;
  }

  .stat {
    flex-direction: row;
    align-items: center;
    gap: 16px;
    padding: 10px 16px;
    text-align: left;
    border: 1.5px solid var(--g-gold-line);
    border-radius: 12px;
    background: rgba(8, 12, 18, 0.35);
    min-height: 0;
  }

  .stat:first-child {
    border-left: 1.5px solid var(--g-gold-line);
  }

  .stat-ic {
    width: 36px;
    height: 36px;
  }

  .stat-text span {
    font-size: 18px;
    font-weight: 500;
  }

  .stat-text strong {
    font-size: 17px;
  }

  .continue-btn {
    min-height: 0;
    height: 100%;
    font-size: 28px;
    gap: 14px;
  }

  .compose {
    padding: 10px 14px 10px 20px;
  }

  .g-actions {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
    gap: 8px;
  }

  .tile {
    flex-direction: row;
    gap: 12px;
    min-height: 50px;
    padding: 8px 12px;
    font-size: 18px;
  }

  .tile .ic {
    width: 26px !important;
    height: 26px !important;
  }

  .tile-picture {
    grid-column: 1 / -1;
  }

  .frame-empty {
    font-size: 24px;
  }
}

/* Very short landscape windows (phones turned sideways) */
@media (max-height: 520px) and (orientation: landscape) {
  #game {
    height: auto;
    min-height: 100dvh;
    grid-template-rows: auto auto 70vh 60vh auto auto auto;
  }
}
