:root {
  /* Cute Fantasy Palette */
  --c-bg: #fffbf0;
  /* Creamy white background */
  --c-text: #5d4a4a;
  /* Soft brown text */
  --c-text-light: #948686;
  --c-primary: #ff9a9e;
  /* Soft Pink */
  --c-primary-dark: #e8868a;
  --c-accent: #a1c4fd;
  /* Soft Blue */
  --c-accent-dark: #8ab0eb;
  --c-card: #ffffff;
  --c-border: #f0e6e6;
  --c-shadow: rgba(94, 75, 75, 0.08);
  --c-shadow-y: rgba(94, 75, 75, 0.15);

  /* Dimensions & Radius */
  --radius-s: 12px;
  --radius-m: 20px;
  --radius-l: 32px;
  --pad: 20px;
  --header-height: 60px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  /* App-like feel */
}

body {
  font-family: "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN", sans-serif;
  background: var(--c-bg);
  color: var(--c-text);
  font-weight: 500;
  display: flex;
  justify-content: center;
}

/* App Container - Mobile Optimization */
.app {
  width: 100%;
  max-width: 430px;
  /* Mobile width constraint */
  height: 100%;
  background: var(--c-bg);
  position: relative;
  overflow-y: auto;
  /* Scrollable content inside wrapper */
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}

/* --- Typography --- */
h1,
h2,
h3 {
  margin: 0;
  line-height: 1.3;
  color: var(--c-text);
}

p {
  margin: 0;
  line-height: 1.6;
}

.logo {
  font-size: 42px;
  font-weight: 800;
  color: var(--c-primary);
  text-align: center;
  text-shadow: 2px 2px 0px #fff, 4px 4px 0px var(--c-accent);
  margin-bottom: 8px;
}

.tag {
  text-align: center;
  color: var(--c-text-light);
  font-size: 14px;
}

.section-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-title::before {
  content: '';
  display: block;
  width: 6px;
  height: 24px;
  background: var(--c-primary);
  border-radius: 4px;
}

/* --- Components --- */

/* Buttons */
.btn {
  appearance: none;
  width: 100%;
  height: 56px;
  /* Tappable area */
  border: 2px solid var(--c-border);
  /* Visible border on all sides */
  border-radius: var(--radius-l);
  background: #fff;
  color: var(--c-text);
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--c-border), 0 8px 16px -4px var(--c-shadow);
  transition: transform 0.1s, box-shadow 0.1s;
  display: grid;
  place-content: center;
  margin-bottom: 4px;
  /* Space for shadow */
}

.btn:active:not(:disabled) {
  transform: translateY(4px);
  box-shadow: 0 0 0 var(--c-border), inset 0 2px 4px rgba(0, 0, 0, 0.05);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
  background: #f5f5f5;
  border-color: #e0e0e0;
  transform: translateY(2px);
}

.btn.primary {
  background: var(--c-primary);
  border-color: var(--c-primary-dark);
  color: white;
  box-shadow: 0 4px 0 var(--c-primary-dark), 0 8px 20px -4px rgba(255, 154, 158, 0.4);
}

.btn.danger {
  background: #fff0f0;
  color: #ff6b6b;
  box-shadow: 0 4px 0 #fadadd;
}

/* Cards / Stack */
.stack,
.playarea,
.modal-card {
  background: var(--c-card);
  border-radius: var(--radius-m);
  padding: 24px;
  box-shadow: 0 8px 24px var(--c-shadow);
  margin-bottom: 20px;
  border: 2px solid #fff;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
  /* Center content in stack by default */
  text-align: center;
}

.stack>* {
  width: 100%;
}

/* Ensure full width children */

/* Inputs / Fields */
.field {
  width: 100%;
  text-align: left;
  margin-bottom: 8px;
}

.field-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--c-text-light);
  margin-bottom: 6px;
  display: block;
}

.select {
  width: 100%;
  height: 48px;
  padding: 0 16px;
  border: 2px solid var(--c-border);
  border-radius: var(--radius-s);
  background: #fff;
  font-family: inherit;
  font-size: 16px;
  color: var(--c-text);
  outline: none;
}

.select:focus {
  border-color: var(--c-accent);
}

/* --- Screens --- */
.screen {
  padding: var(--pad);
  padding-bottom: 100px;
  /* Space for footer/safe area */
  animation: fadeIn 0.4s ease;
}

.screen[hidden] {
  display: none;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* HUD */
.hud {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;
  align-items: center;
  background: #fff;
  border-radius: 16px;
  padding: 8px 12px;
  box-shadow: 0 4px 12px var(--c-shadow);
  margin-bottom: 16px;
  font-weight: 700;
  font-size: 13px;
  border: 2px solid var(--c-border);
  gap: 8px;
}

.hud-stat {
  display: flex;
  align-items: center;
  gap: 4px;
}

.hud-label {
  color: var(--c-text-light);
  font-size: 11px;
  text-transform: uppercase;
}

.coin-stat {
  color: var(--c-accent-dark);
}

/* Play Area */
.playarea {
  min-height: 300px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.mode {
  width: 100%;
}

.mode[hidden] {
  display: none;
}

/* Avatar */
.avatar {
  width: 120px;
  height: 120px;
  margin: 20px auto;
  border-radius: 50%;
  background: linear-gradient(135deg, #fad0c4 0%, #ffd1ff 100%);
  border: 4px solid #fff;
  box-shadow: 0 8px 24px rgba(255, 154, 158, 0.3);
  position: relative;
}

/* Simple playful face using CSS pseudo-elements (Optional cute touch) */
.avatar::before,
.avatar::after {
  content: '';
  position: absolute;
  top: 45%;
  width: 12px;
  height: 12px;
  background: #5d4a4a;
  border-radius: 50%;
}

.avatar::before {
  left: 35%;
}

.avatar::after {
  right: 35%;
}

.playtext {
  text-align: center;
  font-size: 16px;
  color: var(--c-text-light);
  margin-top: 10px;
}

/* POI List */
.poi-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.poi-card {
  appearance: none;
  border: none;
  background: #f8faff;
  padding: 16px;
  border-radius: var(--radius-s);
  text-align: left;
  border: 1px solid #eef2f9;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.poi-card:hover {
  transform: scale(1.02);
  background: #f0f4ff;
}

.poi-card:active {
  transform: scale(0.98);
}

.poi-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--c-accent-dark);
}

.poi-meta {
  font-size: 12px;
  color: var(--c-text-light);
}

/* Log */
.log {
  margin-top: 20px;
  max-height: 200px;
  overflow-y: auto;
  background: rgba(255, 255, 255, 0.5);
  border-radius: var(--radius-s);
  padding: 10px;
}

.log h3 {
  font-size: 12px;
  text-transform: uppercase;
  color: var(--c-text-light);
  letter-spacing: 1px;
  margin-bottom: 8px;
}

#log-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.log-entry {
  font-size: 13px;
  padding: 8px 12px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.03);
}

.log-flavor {
  font-weight: 600;
  margin-bottom: 2px;
}

.log-reward {
  font-size: 11px;
  color: var(--c-accent-dark);
}

.log-empty {
  text-align: center;
  color: var(--c-text-light);
  font-size: 12px;
  padding: 10px;
}

/* Menu Groups */
.menu-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

/* Footer / Sticky controls */
.footer {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  padding: 20px;
  background: linear-gradient(to top, var(--c-bg) 80%, rgba(255, 255, 255, 0));
  pointer-events: none;
  /* Let clicks pass through gradient area */
}

.footer>* {
  pointer-events: auto;
}

/* Re-enable pointer on actual footer content */

/* Autosave Badge */
.save-status {
  position: fixed;
  top: 16px;
  /* Moved to top for better visibility */
  right: 16px;
  left: auto;
  bottom: auto;
  transform: translateY(-10px);
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--c-primary);
  color: var(--c-primary);
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  opacity: 0;
  transition: all 0.3s ease;
  pointer-events: none;
  z-index: 100;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  backdrop-filter: blur(4px);
}

.save-status.visible {
  opacity: 1;
  transform: translateY(0);
}

/* --- Modal (CRITICAL) --- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(93, 74, 74, 0.4);
  backdrop-filter: blur(4px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s, visibility 0.3s;
  pointer-events: none;
  /* IMPORTANT: Pass clicks when hidden */
}

/* State: Open (Using aria-hidden as a reliable hook if available, or just :not([hidden])) */
.modal:not([hidden]) {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  /* IMPORTANT: Catch clicks when visible */
}

.modal-card {
  width: 100%;
  max-width: 360px;
  background: #fff;
  border-radius: var(--radius-l);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
  margin: 0;
  /* Reset stack margin */
  transform: scale(0.9);
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal:not([hidden]) .modal-card {
  transform: scale(1);
}

.modal-card h3 {
  color: var(--c-primary-dark);
  font-size: 20px;
  text-align: center;
  margin-bottom: 12px;
}

.modal-actions {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}

/* Utilities */
.hint {
  font-size: 12px;
  color: var(--c-text-light);
  text-align: center;
}

.hint[hidden] {
  display: none;
}

/* Scrollbar beautification */
::-webkit-scrollbar {
  width: 6px;
}

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

::-webkit-scrollbar-thumb {
  background: var(--c-border);
  border-radius: 3px;
}

/* Fix for grid/flex elements ignoring hidden attribute */
[hidden] {
  display: none !important;
}

/* Inventory & Small Buttons */
.inventory-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px dashed var(--c-border);
}

.inventory-item:last-child {
  border-bottom: none;
}

.btn-sm {
  appearance: none;
  border: 2px solid var(--c-primary);
  background: white;
  color: var(--c-primary);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.1s;
}

.btn-sm.primary {
  background: var(--c-primary);
  color: white;
  box-shadow: 0 2px 0 var(--c-primary-dark);
}

.btn-sm:active {
  transform: translateY(2px);
  box-shadow: none;
}

/* --- Exploration UI --- */
.explore-options {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.explore-options .btn {
  flex: 1;
  font-size: 14px;
}

.timer-display {
  font-size: 48px;
  font-weight: 800;
  color: var(--c-primary);
  text-align: center;
  font-variant-numeric: tabular-nums;
  margin: 10px 0;
  text-shadow: 2px 2px 0px #fff;
}

.explore-progress {
  width: 100%;
  height: 12px;
  border-radius: 6px;
  overflow: hidden;
  border: none;
  background-color: #eef2f9;
}

.explore-progress::-webkit-progress-bar {
  background-color: #eef2f9;
}

.explore-progress::-webkit-progress-value {
  background-color: var(--c-primary);
  border-radius: 6px;
  transition: width 0.3s linear;
}

.status-badge {
  display: inline-block;
  padding: 6px 16px;
  background: #fff0f0;
  color: #ff6b6b;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  border: 1px solid #fadadd;
  margin-top: 8px;
}

.incapacitated-banner {
  background: #ffe3e3;
  border: 2px solid #ff6b6b;
  color: #c92a2a;
  padding: 12px;
  border-radius: var(--radius-m);
  margin-bottom: 16px;
  text-align: center;
  animation: fadeIn 0.3s ease;
}

.incapacitated-banner button {
  margin-top: 6px;
}

/* --- Party UI --- */
.party-card {
  background: #fff;
  border: 2px solid var(--c-border);
  border-radius: var(--radius-m);
  padding: 16px;
  margin-bottom: 12px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.party-card:hover {
  transform: translateY(-2px);
  border-color: var(--c-accent);
  box-shadow: 0 4px 12px var(--c-shadow);
}

.party-info h4 {
  margin: 0 0 4px 0;
  font-size: 16px;
  color: var(--c-text);
}

.party-meta {
  font-size: 13px;
  color: var(--c-text-light);
  display: flex;
  gap: 12px;
}

.party-status {
  text-align: right;
}

.member-count {
  font-weight: 700;
  color: var(--c-primary);
}

.full .member-count {
  color: var(--c-text-light);
}

/* Member List in Lobby */
.member-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.member-card {
  background: #f8faff;
  padding: 12px;
  border-radius: var(--radius-s);
  border: 1px solid #eef2f9;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.member-card.empty {
  background: transparent;
  border: 2px dashed #e0e0e0;
  color: #ccc;
  justify-content: center;
  min-height: 100px;
}

.member-avatar {
  width: 48px;
  height: 48px;
  background: #ddd;
  border-radius: 50%;
}

.member-name {
  font-size: 13px;
  font-weight: 700;
}

/* Static Form Value */
.form-group-static {
  text-align: left;
  margin-bottom: 16px;
  background: #f9f9f9;
  padding: 12px;
  border-radius: var(--radius-s);
  border: 1px solid #eee;
}

.form-group-static label {
  display: block;
  font-size: 12px;
  color: #999;
  font-weight: 700;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.static-value {
  font-size: 16px;
  font-weight: 700;
  color: var(--c-text);
}

/* Exploration Mini List */
.member-list-mini {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 20px;
}

.member-mini {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #eee;
  border: 2px solid #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.timer-large {
  font-size: 64px;
  font-weight: 800;
  color: var(--c-primary);
  text-align: center;
  font-variant-numeric: tabular-nums;
  margin: 20px 0;
}

/* --- Wizard UI --- */
.wizard-step {
  animation: fadeIn 0.3s ease;
}

.input-text {
  width: 100%;
  height: 48px;
  padding: 0 16px;
  border: 2px solid var(--c-border);
  border-radius: var(--radius-s);
  font-size: 16px;
  font-family: inherit;
  outline: none;
  background: #fff;
}

.input-text:focus {
  border-color: var(--c-primary);
}

.error-msg {
  color: #15803d;
  font-size: 18px;
  text-align: left;
  margin-top: 4px;
}

/* World Info (Issue #26) */
.world-card {
  background: rgba(255, 255, 255, 0.9);
  border-radius: var(--radius-m);
  padding: 12px;
  margin-bottom: 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  border: 1px solid rgba(0, 0, 0, 0.1);
}

.world-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px dashed rgba(0, 0, 0, 0.1);
}

.world-title {
  font-size: 10px;
  font-weight: 800;
  color: var(--c-text-light);
  letter-spacing: 0.5px;
}

.world-meta {
  font-size: 13px;
  font-weight: 700;
  color: var(--c-text);
}

.world-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.world-tag {
  font-size: 11px;
  background: #f0f9ff;
  color: #0369a1;
  padding: 3px 8px;
  border-radius: 12px;
  border: 1px solid #bae6fd;
}

.world-rumor {
  display: flex;
  align-items: center;
  background: rgba(0, 0, 0, 0.03);
  padding: 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s;
}

.world-rumor:hover {
  background: rgba(0, 0, 0, 0.06);
}

.rumor-label {
  font-size: 9px;
  font-weight: 800;
  color: white;
  background: #ec4899;
  padding: 2px 4px;
  border-radius: 3px;
  margin-right: 8px;
}

.rumor-text {
  font-size: 12px;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--c-text);
}

/* Route Selector (Issue #27) */
.route-selector {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 16px 0;
}

.route-option {
  display: flex;
  align-items: flex-start;
  background: var(--c-bg-sub);
  padding: 10px;
  border-radius: var(--radius-s);
  border: 2px solid transparent;
  cursor: pointer;
  transition: all 0.2s;
}

.route-option:hover {
  background: rgba(0, 0, 0, 0.05);
}

.route-option input[type="radio"] {
  margin-right: 12px;
  margin-top: 2px;
  transform: scale(1.2);
  accent-color: var(--c-primary);
}

/* Support :has for better styling, otherwise default radio works */
.route-option:has(input:checked) {
  border-color: var(--c-primary);
  background: white;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.route-label {
  display: flex;
  flex-direction: column;
}

.route-label strong {
  font-size: 14px;
  margin-bottom: 2px;
}

.route-label small {
  font-size: 11px;
  color: #666;
  line-height: 1.3;
}

.selection-grid {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-bottom: 20px;
}

.select-card {
  appearance: none;
  background: #fff;
  border: 2px solid var(--c-border);
  border-radius: var(--radius-m);
  padding: 20px;
  width: 100%;
  text-align: center;
  cursor: pointer;
  font-weight: 700;
  transition: all 0.2s;
}

.select-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px var(--c-shadow);
}

.select-card.active {
  border-color: var(--c-primary);
  background: #fff0f0;
  color: var(--c-primary);
}

.selection-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
}

.row {
  display: flex;
  gap: 12px;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  text-align: left;
  font-size: 14px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
}


/* --- Equipment UI (Issue #22) --- */
.equipment-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.slot-card {
  background: var(--c-surface, #fff);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-m);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
}

.slot-card:hover {
  border-color: var(--c-primary);
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.05);
}

.slot-name {
  font-size: 11px;
  color: var(--c-text-light);
  text-transform: uppercase;
  font-weight: 700;
}

.slot-item {
  font-size: 14px;
  font-weight: 600;
  color: var(--c-text);
  min-height: 20px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.slot-item.empty {
  color: #ccc;
  font-style: italic;
  font-weight: 400;
}

/* Stat Preview */
.stat-preview-card {
  margin-bottom: 20px;
  padding: 16px;
  border: 1px solid var(--c-border);
}

.stat-row .diff {
  font-size: 12px;
  font-weight: 700;
  margin-left: 6px;
}

.stat-diff.positive,
.diff.positive {
  color: #40c057;
}

.stat-diff.negative,
.diff.negative {
  color: #fa5252;
}

/* Equipped Badge in Inventory */
.inventory-item.equipped {
  background-color: #f0fdf4;
  /* Light green bg */
  border-color: #40c057;
}

.equipped-badge {
  display: inline-block;
  background: #40c057;
  color: white;
  font-size: 10px;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: 8px;
  vertical-align: middle;
}

/* Locked Button */
.btn.locked {
  filter: grayscale(100%);
  opacity: 0.6;
  cursor: not-allowed;
  position: relative;
}

.btn.locked::after {
  content: "🔒";
  position: absolute;
  top: -5px;
  right: -5px;
  font-size: 14px;
}

/* Announcements (Issue #24) */
.announcement-section {
  width: 100%;
  margin-top: 20px;
  text-align: left;
  background: rgba(255, 255, 255, 0.6);
  border-radius: var(--radius-m);
  padding: 12px;
  border: 1px solid rgba(0, 0, 0, 0.05);
}

.announcement-header {
  font-size: 11px;
  font-weight: 800;
  color: var(--c-text-light);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.announcement-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 200px;
  overflow-y: auto;
}

.announcement-item {
  display: flex;
  align-items: baseline;
  font-size: 13px;
  cursor: pointer;
  padding: 6px;
  border-radius: 4px;
  transition: background 0.2s;
  border-bottom: 1px dotted rgba(0, 0, 0, 0.1);
}

.announcement-item:last-child {
  border-bottom: none;
}

.announcement-item:hover {
  background: rgba(255, 255, 255, 0.8);
}

.announcement-date {
  font-size: 11px;
  font-weight: 700;
  color: var(--c-primary);
  margin-right: 8px;
  white-space: nowrap;
  min-width: 70px;
  /* Aligns content */
}

.announcement-body {
  color: var(--c-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}