: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;
  justify-content: space-between;
  align-items: center;
  background: #fff;
  border-radius: 50px;
  /* Pill shape */
  padding: 8px 16px;
  box-shadow: 0 4px 12px var(--c-shadow);
  margin-bottom: 16px;
  font-weight: 700;
  font-size: 14px;
  border: 2px solid var(--c-border);
}

/* 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;
}