:root {
  /* Core palette */
  --black: #111111;        /* reserved for the display screen only — max legibility */
  --ink: #2B2A28;          /* warm charcoal — used for everyday UI text & buttons */
  --white: #F8F6F2;
  --paper: #FDFCFA;        /* soft warm white for cards, sits slightly above the page bg */
  --gold: #B89B5E;
  --gold-soft: rgba(184,155,94,0.16);
  --gold-softer: rgba(184,155,94,0.08);
  --mist: #D9D9D9;
  --mist-soft: rgba(43,42,40,0.10);
  --mist-softer: rgba(43,42,40,0.06);
  --danger: #A8584C;
  --danger-soft: rgba(168,88,76,0.10);

  --shadow-sm: 0 1px 2px rgba(43,42,40,0.05), 0 2px 8px rgba(43,42,40,0.05);
  --shadow-md: 0 4px 20px rgba(43,42,40,0.08);

  --font-display: 'Cormorant Garamond', Georgia, serif;
  --font-ui: 'Jost', 'Segoe UI', -apple-system, sans-serif;

  --radius: 16px;
  --radius-lg: 20px;
  --gap: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--white);
  background-image: radial-gradient(circle at 15% 0%, rgba(184,155,94,0.05), transparent 45%);
  color: var(--ink);
  font-family: var(--font-ui);
  -webkit-tap-highlight-color: transparent;
}

body {
  overscroll-behavior: none;
}

#app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

button {
  font-family: var(--font-ui);
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
  border-radius: 6px;
}

input, select {
  font-family: var(--font-ui);
}

/* ===================== Screens ===================== */

.screen {
  display: none;
  flex-direction: column;
  height: 100%;
  width: 100%;
}

.screen.is-active {
  display: flex;
}

/* ===================== Topbar ===================== */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 22px 12px;
  flex-shrink: 0;
}

.brand {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 29px;
  margin: 0;
  letter-spacing: 0.01em;
  color: var(--ink);
}

.brand.small {
  font-size: 20px;
}

.brand-dot {
  color: var(--gold);
}

.topbar-spacer {
  width: 42px;
}

.icon-btn {
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--ink);
  flex-shrink: 0;
  transition: background 0.15s ease;
}

.icon-btn:hover {
  background: var(--gold-softer);
}

.icon-btn:active {
  background: var(--gold-soft);
}

/* ===================== Comunicar screen ===================== */

.first-run-note {
  margin: 0 22px 10px;
  padding: 13px 14px;
  background: var(--gold-softer);
  border-radius: var(--radius);
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--ink);
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.link-btn {
  text-decoration: underline;
  text-decoration-color: var(--gold);
  text-underline-offset: 2px;
  font-weight: 600;
  color: var(--ink);
  padding: 0;
}

.note-dismiss {
  flex-shrink: 0;
  font-size: 12px;
  color: var(--ink);
  opacity: 0.45;
  padding: 4px;
  border-radius: 50%;
  line-height: 1;
}

.note-dismiss:hover {
  opacity: 0.8;
  background: rgba(43,42,40,0.06);
}

.category-tabs {
  display: flex;
  gap: 10px;
  padding: 4px 22px 16px;
  overflow-x: auto;
  flex-shrink: 0;
  scrollbar-width: none;
}
.category-tabs::-webkit-scrollbar { display: none; }

.category-tab {
  flex-shrink: 0;
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--paper);
  border: 1.5px solid var(--mist-softer);
  font-size: 14.5px;
  font-weight: 500;
  white-space: nowrap;
  color: var(--ink);
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.category-tab.is-selected {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--white);
}

.phrase-grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--gap);
  padding: 4px 22px 18px;
  align-content: start;
}

@media (min-width: 560px) {
  .phrase-grid { grid-template-columns: repeat(3, 1fr); }
}

.phrase-btn {
  background: var(--paper);
  border: 1px solid var(--mist-softer);
  box-shadow: var(--shadow-sm);
  border-radius: var(--radius-lg);
  padding: 20px 16px;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.35;
  text-align: left;
  min-height: 80px;
  display: flex;
  align-items: center;
  color: var(--ink);
  transition: transform 0.1s ease, background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.phrase-btn:hover {
  border-color: var(--gold);
  box-shadow: var(--shadow-md);
}

.phrase-btn:active {
  transform: scale(0.97);
  background: var(--gold-soft);
  border-color: var(--gold);
  box-shadow: none;
}

.empty-state {
  text-align: center;
  color: #8a8782;
  font-size: 14.5px;
  margin: 30px 22px;
  line-height: 1.5;
}

.composer {
  flex-shrink: 0;
  display: flex;
  gap: 10px;
  padding: 14px 22px calc(18px + env(safe-area-inset-bottom));
  background: var(--white);
  box-shadow: 0 -2px 14px rgba(43,42,40,0.05);
}

.composer input {
  flex: 1;
  border: 1.5px solid var(--mist-softer);
  border-radius: 999px;
  padding: 14px 19px;
  font-size: 16px;
  background: var(--paper);
  color: var(--ink);
  transition: border-color 0.15s ease;
}

.composer input:focus-visible {
  border-color: var(--gold);
}

.btn-primary {
  background: var(--ink);
  color: var(--white);
  border-radius: 999px;
  padding: 14px 24px;
  font-size: 15.5px;
  font-weight: 600;
  flex-shrink: 0;
  transition: background 0.15s ease, color 0.15s ease;
}

.btn-primary:active {
  background: var(--gold);
  color: var(--ink);
}

/* ===================== Display screen ===================== */

#screenDisplay {
  background: var(--white);
  color: var(--black);
  position: relative;
  transition: background 0.2s ease, color 0.2s ease;
}

#screenDisplay.dark-display {
  background: var(--black);
  color: var(--white);
}

.corner {
  position: absolute;
  top: calc(16px + env(safe-area-inset-top));
  z-index: 5;
  background: rgba(128,128,128,0.12);
}

.corner.top-left { left: 16px; }
.corner.top-right { right: 16px; }

.display-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 70px 28px;
  overflow: hidden;
}

.display-text {
  font-family: var(--font-ui);
  font-weight: 700;
  text-align: center;
  line-height: 1.15;
  margin: 0;
  max-width: 100%;
  /* font-size is set dynamically via JS */
}

/* ===================== Settings screen ===================== */

.settings-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 4px 22px calc(40px + env(safe-area-inset-bottom));
}

.settings-section {
  background: var(--paper);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 22px;
  margin-bottom: 18px;
}

.settings-section h2 {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--gold);
  margin: 0 0 16px;
  font-weight: 600;
}

.hint {
  font-size: 13.5px;
  color: #8a8782;
  line-height: 1.55;
  margin: -8px 0 16px;
}

.switch-row, .select-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 0;
  font-size: 15.5px;
  gap: 16px;
  color: var(--ink);
}

.switch-row + .switch-row,
.select-row + .switch-row,
.switch-row + .select-row {
  border-top: 1px solid var(--mist-softer);
}

/* Custom calm toggle switch */
.switch {
  position: relative;
  display: inline-flex;
  width: 48px;
  height: 28px;
  flex-shrink: 0;
}

.switch input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
  cursor: pointer;
  z-index: 2;
}

.switch-track {
  position: absolute;
  inset: 0;
  background: var(--mist-soft);
  border-radius: 999px;
  transition: background 0.2s ease;
}

.switch-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  background: var(--white);
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(43,42,40,0.25);
  transition: transform 0.2s ease;
}

.switch input:checked ~ .switch-track {
  background: var(--gold);
}

.switch input:checked ~ .switch-track .switch-thumb {
  transform: translateX(20px);
}

.switch input:focus-visible ~ .switch-track {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

.select-row select {
  flex: 1;
  max-width: 60%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1.5px solid var(--mist-softer);
  background: var(--white);
  color: var(--ink);
}

/* Category editor in settings */

.category-block {
  background: var(--white);
  border-radius: var(--radius);
  margin-bottom: 14px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.category-block-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 14px;
  background: var(--gold-softer);
}

.category-block-head input[type="text"] {
  flex: 1;
  min-width: 0;
  border: none;
  background: none;
  font-weight: 600;
  font-size: 15.5px;
  padding: 4px 0;
  color: var(--ink);
}

.category-emoji-input {
  width: 38px;
  text-align: center;
  border: none;
  background: none;
  font-size: 16px;
}

.btn-icon-text {
  font-size: 17px;
  color: var(--danger);
  white-space: nowrap;
  padding: 6px 8px;
  flex-shrink: 0;
  background: none;
  border-radius: 50%;
  transition: background 0.15s ease;
}

.btn-icon-text:hover {
  background: var(--danger-soft);
}

.phrase-list {
  padding: 12px 14px 14px;
}

.phrase-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
}

.phrase-row input[type="text"] {
  flex: 1;
  border: 1.5px solid var(--mist-softer);
  border-radius: 10px;
  padding: 10px 13px;
  font-size: 14.5px;
  color: var(--ink);
  background: var(--paper);
}

.phrase-row button {
  font-size: 17px;
  color: var(--danger);
  padding: 6px 9px;
  flex-shrink: 0;
  border-radius: 50%;
  transition: background 0.15s ease;
}

.phrase-row button:hover {
  background: var(--danger-soft);
}

.add-phrase-row {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.add-phrase-row input {
  flex: 1;
  border: 1.5px dashed var(--gold);
  border-radius: 10px;
  padding: 10px 13px;
  font-size: 14.5px;
  background: var(--gold-softer);
  color: var(--ink);
}

.add-phrase-row button {
  background: var(--gold);
  color: var(--ink);
  border-radius: 10px;
  padding: 0 16px;
  font-weight: 600;
  font-size: 14px;
}

.inline-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.inline-form input[type="text"] {
  border: 1.5px solid var(--mist-softer);
  border-radius: 10px;
  padding: 12px 15px;
  font-size: 15px;
  background: var(--white);
  color: var(--ink);
}

#newCategoryName { flex: 1; min-width: 140px; }
.emoji-input { width: 68px; text-align: center; }

.btn-secondary {
  background: var(--ink);
  color: var(--white);
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 14.5px;
  font-weight: 600;
  transition: background 0.15s ease, color 0.15s ease;
}

.btn-secondary:active {
  background: var(--gold);
  color: var(--ink);
}

.btn-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.btn-text {
  font-size: 13.5px;
  text-decoration: underline;
  text-underline-offset: 2px;
  padding: 6px 0;
  color: var(--ink);
  opacity: 0.7;
}

.btn-text.danger {
  color: var(--danger);
  opacity: 1;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
