:root {
  color-scheme: dark;
  font-family: "Hiragino Sans", "Yu Gothic", "Meiryo", system-ui, sans-serif;
  background: #0d1320;
  color: #f8fafc;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 12% 12%, rgba(80, 116, 170, 0.22), transparent 26rem),
    radial-gradient(circle at 90% 8%, rgba(185, 144, 95, 0.14), transparent 24rem),
    #0d1320;
}

.app {
  position: relative;
  width: 100%;
  min-height: 100svh;
  padding: max(14px, env(safe-area-inset-top)) 16px max(14px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 14px;
  place-items: center;
}

.phone-shell {
  width: 86vw;
  max-width: 430px;
  height: clamp(390px, 60svh, 690px);
  display: grid;
  place-items: center;
}

.wallpaper {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  border-radius: 28px;
  background: var(--bg);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.48);
  isolation: isolate;
}

.wallpaper::before,
.wallpaper::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.wallpaper::before {
  background: var(--overlay);
  opacity: var(--overlay-opacity, 1);
  z-index: 1;
}

.wallpaper::after {
  background:
    linear-gradient(180deg, rgba(0, 0, 0, 0.22), transparent 30%, rgba(0, 0, 0, 0.4)),
    radial-gradient(circle at 50% 120%, rgba(255, 255, 255, 0.16), transparent 24rem);
  z-index: 2;
}

.grain {
  position: absolute;
  inset: -40px;
  z-index: 3;
  opacity: 0.13;
  background-image:
    radial-gradient(circle at 20% 30%, rgba(255, 255, 255, 0.3) 0 1px, transparent 1px),
    radial-gradient(circle at 72% 64%, rgba(255, 255, 255, 0.24) 0 1px, transparent 1px);
  background-size: 34px 34px, 47px 47px;
  transform: rotate(-8deg);
}

.wallpaper-content {
  position: relative;
  z-index: 4;
  min-height: 100%;
  padding: clamp(46px, 8svh, 76px) 32px clamp(44px, 7svh, 68px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
  text-shadow: 0 3px 18px rgba(0, 0, 0, 0.34);
}

.quote-category {
  align-self: center;
  margin: 0 0 22px;
  padding: 5px 12px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  background: rgba(5, 10, 20, 0.18);
  font-size: 12px;
  line-height: 1.5;
  font-weight: 800;
  letter-spacing: 0;
  color: rgba(255, 255, 255, 0.72);
}

.quote {
  margin: 0;
  max-width: 100%;
  white-space: pre-line;
  font-size: clamp(21px, var(--quote-size, 6.3vw), 36px);
  line-height: 1.52;
  font-weight: 800;
  letter-spacing: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-break: strict;
}

.controls {
  width: 86vw;
  max-width: 430px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}

.category-control {
  grid-column: 1 / -1;
  min-height: 50px;
  padding: 8px 12px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
}

.category-control span {
  font-size: 12px;
  font-weight: 800;
  color: rgba(255, 255, 255, 0.62);
}

.category-control select {
  width: 100%;
  min-width: 0;
  border: 0;
  background: transparent;
  color: #f8fafc;
  font: inherit;
  font-size: 15px;
  font-weight: 800;
  outline: none;
}

.category-control option {
  color: #111827;
  background: #f8fafc;
}

.button,
.icon-button,
.favorite-item,
.manage-button {
  font: inherit;
  letter-spacing: 0;
  cursor: pointer;
}

.button {
  appearance: none;
  min-height: 50px;
  border: 0;
  border-radius: 8px;
  padding: 0 14px;
  font-size: 15px;
  font-weight: 800;
  transition: transform 0.16s ease, filter 0.16s ease, background 0.16s ease;
}

.button:active,
.icon-button:active,
.favorite-item:active,
.manage-button:active {
  transform: translateY(1px) scale(0.99);
}

.button-primary {
  color: #10131a;
  background: #f8fafc;
}

.button-secondary {
  color: #f8fafc;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.18);
}

.button-secondary[aria-pressed="true"] {
  background: rgba(185, 144, 95, 0.28);
  border-color: rgba(235, 210, 170, 0.42);
  color: #fff6df;
}

.button-wide {
  grid-column: 1 / -1;
}

.button.is-saving {
  filter: brightness(1.16);
}

.save-status {
  grid-column: 1 / -1;
  margin: -2px 0 0;
  color: rgba(255, 255, 255, 0.66);
  font-size: 12px;
  line-height: 1.5;
  text-align: center;
}

.quote-form {
  grid-column: 1 / -1;
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.07);
}

.form-field {
  display: grid;
  gap: 6px;
}

.form-field span,
.form-message {
  font-size: 12px;
  line-height: 1.5;
  font-weight: 800;
  color: rgba(255, 255, 255, 0.66);
}

.form-field textarea,
.form-field select {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  padding: 11px 12px;
  color: #f8fafc;
  background: rgba(3, 7, 18, 0.34);
  font: inherit;
  font-size: 15px;
  line-height: 1.6;
  outline: none;
}

.form-field textarea {
  min-height: 96px;
  resize: vertical;
}

.form-field select option {
  color: #111827;
  background: #f8fafc;
}

.form-message {
  margin: 0;
  color: rgba(235, 210, 170, 0.9);
}

.form-message.is-error {
  color: #ffc9c9;
}

.form-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}

.data-panel {
  gap: 12px;
}

.data-actions {
  display: grid;
  gap: 9px;
}

.help-panel {
  gap: 0;
}

.help-list {
  margin: 0;
  padding-left: 1.15em;
  color: rgba(255, 255, 255, 0.76);
  font-size: 13px;
  line-height: 1.75;
}

.help-list li + li {
  margin-top: 6px;
}

.favorites-panel {
  position: fixed;
  inset: auto 12px max(12px, env(safe-area-inset-bottom));
  z-index: 10;
  width: min(430px, calc(100% - 24px));
  max-height: min(64svh, 560px);
  padding: 14px;
  overflow: auto;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  background: rgba(13, 19, 32, 0.96);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.52);
  backdrop-filter: blur(16px);
}

.favorites-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.favorites-header h2 {
  margin: 0;
  font-size: 16px;
  line-height: 1.4;
}

.icon-button {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  color: #f8fafc;
  background: rgba(255, 255, 255, 0.08);
  font-size: 22px;
  line-height: 1;
}

.favorites-list {
  display: grid;
  gap: 8px;
}

.favorites-section {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.favorites-section h3 {
  margin: 0 0 10px;
  color: rgba(255, 255, 255, 0.76);
  font-size: 13px;
  line-height: 1.5;
}

.favorite-item {
  width: 100%;
  padding: 13px;
  display: grid;
  gap: 6px;
  text-align: left;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  color: #f8fafc;
  background: rgba(255, 255, 255, 0.06);
}

.favorite-category {
  font-size: 12px;
  line-height: 1.4;
  font-weight: 800;
  color: rgba(235, 210, 170, 0.82);
}

.favorite-text {
  white-space: pre-line;
  font-size: 13px;
  line-height: 1.7;
  font-weight: 700;
}

.quote-manage-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 4px;
}

.manage-button {
  min-height: 38px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  color: #f8fafc;
  background: rgba(255, 255, 255, 0.08);
  font-size: 13px;
  font-weight: 800;
}

.manage-button-danger {
  color: #ffe8e8;
  border-color: rgba(255, 130, 130, 0.28);
  background: rgba(255, 100, 100, 0.12);
}

.empty-state {
  margin: 8px 0 2px;
  color: rgba(255, 255, 255, 0.68);
  font-size: 14px;
  line-height: 1.7;
}

@media (max-width: 360px) {
  .app {
    padding-inline: 12px;
  }

  .phone-shell {
    height: clamp(360px, 56svh, 520px);
  }

  .wallpaper-content {
    padding-inline: 23px;
  }

  .button,
  .category-control select {
    font-size: 14px;
  }

  .button {
    padding-inline: 8px;
  }
}

@media (min-height: 820px) {
  .phone-shell {
    height: min(66svh, 720px);
  }
}
