:root {
  --cream: #f5ede3;
  --tea: #8b6f47;
  --tea-dark: #6b4f3a;
  --leaf: #5a7a4e;
  --text: #3d2e24;
  --radius: 12px;
  --shadow: 0 2px 12px rgb(107 79 58 / 12%);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  color: var(--text);
  background: var(--cream);
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

#app {
  min-height: 100dvh;
}

h1,
h2,
h3 {
  margin: 0 0 0.75rem;
  font-weight: 600;
  color: var(--tea-dark);
  line-height: 1.25;
}

h1 {
  font-size: 1.5rem;
}

.login-title {
  text-align: center;
}

a {
  color: var(--tea-dark);
}

img {
  max-width: 100%;
  height: auto;
  display: block;
}

.app-shell {
  max-width: 32rem;
  margin: 0 auto;
  padding: 1rem 1rem 5.5rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 44px;
  min-width: 44px;
  padding: 0.625rem 1.25rem;
  border: none;
  border-radius: var(--radius);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.btn-primary {
  width: 100%;
  color: var(--cream);
  background: var(--tea-dark);
}

.btn-primary:active {
  background: var(--tea);
}

.btn-secondary {
  color: var(--tea-dark);
  background: #fff;
  box-shadow: inset 0 0 0 1px rgb(107 79 58 / 25%);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.field label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--tea-dark);
}

.field input,
.field select,
.field textarea {
  min-height: 44px;
  padding: 0.625rem 0.875rem;
  border: 1px solid rgb(107 79 58 / 30%);
  border-radius: var(--radius);
  font: inherit;
  color: var(--text);
  background: #fff;
}

.field textarea {
  min-height: 6rem;
  resize: vertical;
}

.list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

.home-controls {
  display: grid;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  width: 100%;
  padding: 0.2rem;
  border-radius: var(--radius);
  background: rgb(107 79 58 / 10%);
}

.segmented--two {
  grid-template-columns: repeat(2, 1fr);
  margin-bottom: 1rem;
}

.segmented__button {
  width: 100%;
  min-height: 44px;
  padding: 0.4rem 0.75rem;
  border: 0;
  border-radius: calc(var(--radius) - 3px);
  font: inherit;
  font-weight: 600;
  color: var(--tea-dark);
  background: transparent;
  cursor: pointer;
}

.segmented__button[aria-pressed="true"] {
  font-weight: 600;
  background: #fff;
  box-shadow: var(--shadow);
}

.home-sort {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--tea-dark);
}

.home-sort select,
.home-search {
  min-height: 44px;
  padding: 0.625rem 0.75rem;
  border: 1px solid rgb(107 79 58 / 30%);
  border-radius: var(--radius);
  font: inherit;
  color: var(--text);
  background: #fff;
}

.home-sort select {
  flex: 1;
}

.home-search {
  width: 100%;
}

.card {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  min-height: 72px;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow);
  text-decoration: none;
  color: inherit;
}

.card:active {
  background: #faf6f0;
}

.card-thumb {
  flex-shrink: 0;
  width: 64px;
  height: 64px;
  overflow: hidden;
  border-radius: calc(var(--radius) - 2px);
  background: var(--cream);
}

.card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card-body {
  flex: 1;
  min-width: 0;
}

.card-title {
  overflow: hidden;
  font-weight: 600;
  color: var(--tea-dark);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-meta {
  min-height: 1.2rem;
  font-size: 0.8125rem;
  color: rgb(61 46 36 / 72%);
}

.card-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.25rem;
}

.card-row .stars {
  margin-right: auto;
}

.card-row .star {
  font-size: 1rem;
}

.card-row time {
  font-size: 0.75rem;
  color: rgb(61 46 36 / 65%);
}

.card__thumb {
  flex-shrink: 0;
  width: 56px;
  height: 56px;
  border-radius: calc(var(--radius) - 2px);
  object-fit: cover;
  background: var(--cream);
}

.card__body {
  flex: 1;
  min-width: 0;
}

.card__title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--tea-dark);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card__meta {
  margin: 0.15rem 0 0;
  font-size: 0.8125rem;
  color: rgb(61 46 36 / 72%);
}

.fab {
  position: fixed;
  right: 1.25rem;
  bottom: calc(1.25rem + var(--safe-bottom));
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border: none;
  border-radius: 50%;
  font-size: 1.75rem;
  font-weight: 300;
  line-height: 1;
  color: var(--cream);
  background: var(--leaf);
  box-shadow: 0 4px 16px rgb(90 122 78 / 45%);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.fab:active {
  transform: scale(0.96);
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--cream);
  background: var(--tea);
}

.empty-state {
  padding: 2rem 1rem;
  text-align: center;
  color: rgb(61 46 36 / 65%);
}

.badge {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--cream);
  background: var(--tea);
}

.stars {
  display: inline-flex;
  align-items: center;
  gap: 0.125rem;
  line-height: 1;
}

.star {
  font-size: 1.25rem;
  line-height: 1;
}

.star-full {
  color: var(--tea);
}

.star-half {
  background: linear-gradient(90deg, var(--tea) 50%, rgb(139 111 71 / 38%) 50%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.star-empty {
  color: rgb(139 111 71 / 38%);
}

.stars-input {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.stars-input__zero {
  min-width: 44px;
  padding: 0.5rem 0.75rem;
}

.stars-input__stars {
  display: flex;
  align-items: center;
  gap: 0.125rem;
}

.star-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0.25rem;
  border: none;
  border-radius: calc(var(--radius) - 4px);
  font-size: 1.5rem;
  line-height: 1;
  color: rgb(139 111 71 / 38%);
  background: transparent;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.star-btn--full,
.star-btn--half {
  color: var(--tea);
}

.star-btn--half {
  background: linear-gradient(90deg, var(--tea) 50%, rgb(139 111 71 / 38%) 50%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.star-btn:active {
  background-color: rgb(139 111 71 / 12%);
}

.app-bar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.5rem;
  margin: -0.25rem 0 1rem;
  min-height: 44px;
}

.app-bar__spacer {
  width: 44px;
}

.app-bar__back {
  min-width: 44px;
  padding: 0.5rem 0.75rem;
  font-size: 1.25rem;
  line-height: 1;
}

.app-bar__title {
  margin: 0;
  font-size: 1.125rem;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-bar__actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.35rem;
  min-width: 44px;
}

.app-bar__action {
  min-height: 44px;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
}

.app-shell__main {
  display: block;
}

.new-form section {
  margin-bottom: 1.25rem;
}

.tea-results {
  display: grid;
  gap: 0.5rem;
  max-height: 15rem;
  overflow-y: auto;
}

.tea-result {
  min-height: 44px;
  padding: 0.625rem 0.75rem;
  border: 1px solid rgb(107 79 58 / 20%);
  border-radius: var(--radius);
  font: inherit;
  text-align: left;
  color: var(--text);
  background: #fff;
  cursor: pointer;
}

.tea-result[aria-pressed="true"] {
  border-color: var(--leaf);
  box-shadow: inset 0 0 0 1px var(--leaf);
}

.field-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.check-field {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  width: 100%;
  min-height: 52px;
  margin-bottom: 0.5rem;
  padding: 0.7rem 1rem;
  border-radius: var(--radius);
  font-weight: 600;
  color: var(--tea-dark);
  background: #fff;
  box-shadow: inset 0 0 0 1px rgb(107 79 58 / 20%);
  cursor: pointer;
  user-select: none;
}

.check-field:has(input:checked) {
  color: var(--leaf);
  background: rgb(90 122 78 / 12%);
  box-shadow: inset 0 0 0 2px var(--leaf);
}

.check-field input {
  width: 1.35rem;
  height: 1.35rem;
  margin: 0;
  accent-color: var(--leaf);
  flex: none;
}

.selected-tea {
  margin: 0 0 1rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-weight: 600;
  color: var(--tea-dark);
  background: #fff;
  box-shadow: var(--shadow);
}

.tea-detail {
  display: grid;
  gap: 1.25rem;
}

.tea-summary,
.tea-averages {
  padding: 1rem;
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow);
}

.tea-summary .btn {
  margin-top: 0.25rem;
}

.tea-average {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.625rem;
  padding: 0.625rem 0;
  border-top: 1px solid rgb(107 79 58 / 12%);
}

.tea-average--global {
  grid-template-columns: 1fr auto;
}

.tea-average span {
  font-size: 0.875rem;
  color: rgb(61 46 36 / 72%);
}

.tea-history h2 {
  margin-top: 0.25rem;
}

.tasting-detail {
  display: grid;
  gap: 1rem;
}

.tasting-summary,
.tasting-readonly,
.tasting-edit-form,
.tasting-photo,
.danger-zone {
  padding: 1rem;
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow);
}

.tasting-summary p {
  margin: -0.5rem 0 0.75rem;
  color: rgb(61 46 36 / 72%);
}

.tasting-rating {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.tasting-photos {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.tasting-photo {
  display: grid;
  align-content: start;
  gap: 0.75rem;
  padding: 0.75rem;
}

.tasting-photo img {
  width: 100%;
  aspect-ratio: 1;
  border-radius: calc(var(--radius) - 3px);
  object-fit: cover;
}

.tasting-photo__empty {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  margin: 0;
  border-radius: calc(var(--radius) - 3px);
  color: rgb(61 46 36 / 65%);
  background: var(--cream);
}

.tasting-photo__controls {
  display: grid;
  gap: 0.5rem;
}

.photo-pickers {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.photo-picker {
  position: relative;
}

.photo-picker__input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  border: 0;
}

.photo-picker__frame {
  display: grid;
  grid-template: 1fr / 1fr;
  place-items: center;
  aspect-ratio: 1;
  overflow: hidden;
  border: 1.5px dashed rgb(107 79 58 / 35%);
  border-radius: var(--radius);
  color: var(--tea-dark);
  background: #fff;
  cursor: pointer;
}

.photo-picker__input:focus-visible + .photo-picker__frame {
  outline: 2px solid var(--leaf);
  outline-offset: 2px;
}

.photo-picker__empty[hidden],
.photo-picker__preview[hidden],
.photo-picker__clear[hidden],
.photo-picker--filled .photo-picker__empty,
.photo-picker:not(.photo-picker--filled) .photo-picker__preview,
.photo-picker:not(.photo-picker--filled) .photo-picker__clear {
  display: none;
}

.photo-picker--filled .photo-picker__frame {
  border-style: solid;
  border-color: transparent;
}

.photo-picker__empty {
  display: grid;
  grid-area: 1 / 1;
  justify-items: center;
  align-content: center;
  gap: 0.15rem;
  padding: 0.75rem;
  text-align: center;
}

.photo-picker__icon {
  display: grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 999px;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--cream);
  background: var(--leaf);
}

.photo-picker__title {
  font-weight: 600;
}

.photo-picker__hint {
  font-size: 0.8125rem;
  font-weight: 500;
  color: rgb(61 46 36 / 62%);
}

.photo-picker__preview {
  grid-area: 1 / 1;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-picker__clear {
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border: 0;
  border-radius: 999px;
  font-size: 1.35rem;
  line-height: 1;
  color: #fff;
  background: rgb(61 46 36 / 72%);
  cursor: pointer;
}

.photo-picker__choose {
  position: relative;
  width: 100%;
}

.tasting-photo__controls input {
  width: 100%;
  font: inherit;
}

.tasting-photo__controls .btn {
  width: 100%;
  padding-inline: 0.5rem;
  font-size: 0.8125rem;
}

.tasting-readonly dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.5rem 1rem;
  margin: 0;
}

.tasting-readonly dt {
  font-weight: 600;
  color: var(--tea-dark);
}

.tasting-readonly dd {
  margin: 0;
  white-space: pre-wrap;
}

.danger-zone {
  border: 1px solid rgb(145 45 45 / 28%);
}

.btn-danger {
  width: 100%;
  color: #fff;
  background: #912d2d;
}

.toast-host {
  position: fixed;
  left: 50%;
  bottom: calc(1.25rem + var(--safe-bottom));
  z-index: 100;
  max-width: min(24rem, calc(100vw - 2rem));
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-size: 0.9375rem;
  font-weight: 500;
  text-align: center;
  color: var(--cream);
  background: var(--tea-dark);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 0.75rem);
  transition:
    opacity 0.2s ease,
    transform 0.2s ease;
}

.toast-host--visible {
  opacity: 1;
  transform: translate(-50%, 0);
}