:root {
    --bg: #1a1512;
    --fg: #f2e9e1;
    --card: #2b221e;
    --accent: #c69c6d;
    --danger: #e76f51;
    --ok: #81b29a;
}
* { box-sizing: border-box; }
html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--fg);
    line-height: 1.5;
    padding-bottom: 2rem;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    overscroll-behavior-y: none;
    touch-action: manipulation;
}
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    padding-top: calc(1rem + env(safe-area-inset-top));
    background: var(--card);
    border-bottom: 1px solid #3e322c;
    position: sticky;
    top: 0;
    z-index: 1;
}
.brand {
    font-size: 1.3rem;
    font-weight: bold;
    color: var(--accent);
    text-decoration: none;
}
.sync-status {
    font-size: 0.7rem;
    color: #a89f99;
    margin-left: 0.5rem;
    flex: 1;
}
nav {
    display: flex;
    align-items: center;
    white-space: nowrap;
}
nav a {
    color: var(--fg);
    margin-left: 0.6rem;
    text-decoration: none;
    font-size: 0.85rem;
}
.loc-toggle {
    display: inline-flex;
    gap: 0;
    margin-right: 0.5rem;
    background: transparent;
    padding: 0;
}
.loc-btn {
    background: #3e322c;
    color: var(--fg);
    border: 1px solid #3e322c;
    padding: 0.4rem 0.55rem;
    font-size: 0.8rem;
    margin: 0;
    border-radius: 0;
    font-weight: normal;
    min-height: 32px;
}
.loc-btn:first-child { border-radius: 6px 0 0 6px; }
.loc-btn:last-child { border-radius: 0 6px 6px 0; }
.loc-btn.active {
    background: var(--accent);
    color: #1a1512;
    font-weight: bold;
}
.loc-tag {
    display: inline-block;
    background: #3e322c;
    color: var(--accent);
    font-size: 0.7rem;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    text-transform: capitalize;
    margin-right: 0.3rem;
}
main {
    padding: 1rem;
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
    padding-bottom: calc(2rem + env(safe-area-inset-bottom));
    max-width: 600px;
    margin: 0 auto;
}
h1, h2 { margin-top: 1.5rem; }
.grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    grid-auto-rows: 1fr;
    gap: 1rem;
    margin: 1rem 0;
}
.card {
    display: flex;
    flex-direction: column;
    min-height: 260px;
    background: var(--card);
    border-radius: 10px;
    padding: 1rem;
    color: var(--fg);
    text-decoration: none;
    text-align: center;
    border: 1px solid #3e322c;
}
.card-add {
    border-style: dashed;
    color: var(--accent);
    justify-content: center;
}
.card-add .card-title { font-size: 2rem; min-height: auto; }
.card-title { font-weight: bold; min-height: 3em; }
.card.brown { border-top: 6px solid #8b5a2b; }
.card.pink { border-top: 6px solid #d87093; }
.bean-thumb {
    width: 100%;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    border-radius: 6px;
    margin: 0.5rem 0;
}
.card-meta {
    font-size: 0.85rem;
    color: #a89f99;
    margin-bottom: 0.5rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.card-actions {
    margin-top: auto;
    display: flex;
    gap: 0.5rem;
    justify-content: center;
}
.card-actions form { display: contents; }
.card-actions .btn {
    flex: 1;
    padding: 0.4rem 0.2rem;
    font-size: 0.75rem;
    margin: 0;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.btn, button {
    display: inline-block;
    background: var(--accent);
    color: #1a1512;
    border: none;
    padding: 0.6rem 1.2rem;
    border-radius: 6px;
    font-weight: bold;
    cursor: pointer;
    text-decoration: none;
    font-size: 1rem;
    margin: 0.5rem 0;
}
.btn.danger, button.danger {
    background: var(--danger);
    color: #fff;
}
/* Small variant — overrides base cleanly with higher specificity */
.btn.small, button.small, .btn.small.danger, button.small.danger {
    padding: 0.3rem 0.7rem;
    font-size: 0.85rem;
    margin: 0;
}
/* Inline buttons in lists — no margin */
.shot-list .btn, .bean-list .btn,
.inline-form .btn, .inline-form button {
    padding: 0.3rem 0.7rem;
    font-size: 0.85rem;
    margin: 0;
}
form {
    background: var(--card);
    padding: 1rem;
    border-radius: 10px;
}
.form-actions-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.5rem;
}
.form-actions-row .btn, .form-actions-row button {
    margin: 0;
}
.form-actions-row .actions-group {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}
.btn-cancel {
    display: inline-block;
    background: transparent;
    color: #a89f99;
    border: 1px solid #3e322c;
    padding: 0.5rem 0.9rem;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: normal;
    text-decoration: none;
    margin: 0;
}
.form-row {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.2rem;
}
.form-field {
    flex: 1;
}
.form-field label {
    margin: 0.8rem 0 0.3rem;
    font-size: 0.8rem;
}
.checks-row {
    display: flex;
    gap: 0.5rem;
    margin: 0.5rem 0;
}
.checks-row .check {
    margin: 0;
    flex: 1;
    flex-direction: row;
    align-items: center;
}
label {
    display: block;
    margin: 0.8rem 0 0.3rem;
    font-size: 0.9rem;
}
input, select, textarea {
    width: 100%;
    padding: 0.6rem;
    border: 1px solid #3e322c;
    border-radius: 6px;
    background: #1a1512;
    color: var(--fg);
    font-size: 1rem;
}
input.invalid, textarea.invalid {
    border-color: #ff6b6b;
}
.readonly-field {
    padding: 0.6rem;
    border: 1px solid #3e322c;
    border-radius: 6px;
    background: #1a1512;
    color: var(--fg);
    font-size: 1rem;
}
.cropper-frame {
    width: 100%;
    max-width: 280px;
    aspect-ratio: 4 / 3;
    overflow: hidden;
    border-radius: 6px;
    border: 1px solid #3e322c;
    background: #1a1512;
    position: relative;
    touch-action: none;
    margin: 0 auto;
}
.cropper-frame img {
    position: absolute;
    top: 50%;
    left: 50%;
    transform-origin: center center;
    user-select: none;
    -webkit-user-drag: none;
    pointer-events: none;
    max-width: none;
}
.cropper-controls {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    margin: 0.5rem 0;
}
.recent-notes {
    background: #1a1512;
    border: 1px solid #3e322c;
    border-radius: 6px;
    padding: 0.6rem;
    margin: 0.5rem 0;
}
.recent-notes h3 {
    font-size: 0.8rem;
    color: var(--accent);
    margin: 0 0 0.3rem;
    text-transform: uppercase;
}
.recent-note {
    font-size: 0.85rem;
    color: #a89f99;
    padding: 0.2rem 0;
    border-bottom: 1px solid #3e322c;
}
.recent-note:last-child { border-bottom: none; }
.recent-stats { color: var(--fg); margin-right: 0.3rem; }
.recent-taste {
    font-style: italic;
    color: var(--accent);
    margin-top: 0.1rem;
}
.roaster-form {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    padding: 0.5rem;
}
.roaster-form input { flex: 1; margin: 0; }
.roaster-form button { margin: 0; white-space: nowrap; }
.roaster-list {
    list-style: none;
    padding: 0;
    margin: 1rem 0;
}
.roaster-list li {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--card);
    margin: 0.5rem 0;
    padding: 0.6rem 0.8rem;
    border-radius: 8px;
    border: 1px solid #3e322c;
}
.roaster-list a {
    flex: 1;
    color: var(--accent);
    text-decoration: none;
}
.check {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 1rem 0;
}
.check input {
    width: auto;
}
.shot-list, .bean-list {
    list-style: none;
    padding: 0;
    margin: 1rem 0;
}
.shot-list li, .bean-list li {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--card);
    margin: 0.5rem 0;
    padding: 0.8rem;
    border-radius: 8px;
    border: 1px solid #3e322c;
}
.shot-list a, .bean-list a {
    flex: 1;
    color: var(--fg);
    text-decoration: none;
}
.shot-item {
    flex-direction: column;
    align-items: stretch;
    gap: 0.2rem;
    padding: 0.5rem 0.6rem;
}
.shot-row1, .shot-row2, .shot-row3, .shot-row4 {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}
.shot-row1 { justify-content: space-between; }
.shot-row2 { justify-content: flex-start; }
.shot-row3 { justify-content: flex-start; }
.shot-row4 { justify-content: center; }
.shot-notes {
    padding: 0 0.6rem;
    font-size: 0.9rem;
    color: var(--accent);
    font-style: italic;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
}
.shot-name {
    color: var(--fg);
    text-decoration: none;
    font-weight: bold;
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}
.shot-time {
    color: #a89f99;
    font-size: 0.75rem;
    white-space: nowrap;
    flex: 0 0 auto;
}
.shot-stats {
    color: #a89f99;
    font-size: 0.8rem;
    white-space: nowrap;
    flex: 0 0 auto;
}
.shot-rate {
    display: flex;
    gap: 0.1rem;
    user-select: none;
    flex: 0 0 auto;
}
.star-sm {
    background: transparent;
    border: none;
    color: #3e322c;
    cursor: pointer;
    padding: 0.15rem;
    font-size: 1.3rem;
    margin: 0;
    line-height: 1;
    min-width: 28px;
    min-height: 28px;
}
.star-sm.filled { color: var(--accent); }
.shot-taste { flex: 0 0 auto; }
.taste-btn {
    background: transparent;
    border: 1px solid #3e322c;
    color: #a89f99;
    padding: 0.15rem 0.4rem;
    font-size: 0.7rem;
    border-radius: 4px;
    cursor: pointer;
    margin: 0;
    max-width: 100%;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
    white-space: nowrap;
    display: inline-block;
    box-sizing: border-box;
    flex: 0 0 auto;
}
.taste-btn.has-notes {
    color: var(--fg);
    border-color: var(--accent);
    font-style: italic;
}
.shot-item.pending {
    opacity: 0.7;
    border: 1px dashed var(--accent);
}
.sync-badge {
    font-size: 0.75rem;
    color: var(--accent);
    font-style: italic;
}
.sync-badge.failed {
    color: var(--danger);
}
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}
.modal {
    background: var(--card);
    border-radius: 10px;
    padding: 1.5rem;
    width: 90%;
    max-width: 400px;
    border: 1px solid #3e322c;
}
.modal h3 { margin: 0 0 0.5rem; color: var(--accent); }
.modal textarea {
    width: 100%;
    margin: 0.5rem 0;
    background: #1a1512;
    color: var(--fg);
    border: 1px solid #3e322c;
    border-radius: 6px;
    padding: 0.6rem;
    font-size: 1rem;
}
.modal-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    margin-top: 0.5rem;
}
.rating { color: var(--ok); font-weight: bold; margin-left: 0.5rem; }
.unrated { color: var(--danger); font-size: 0.85rem; margin-left: 0.5rem; }
.stars { color: var(--accent); letter-spacing: 2px; margin-left: 0.3rem; }
.taste-notes {
    font-size: 0.85rem;
    color: #a89f99;
    margin-top: 0.3rem;
    font-style: italic;
}
.star-rating {
    display: flex;
    gap: 0.2rem;
    font-size: 1.8rem;
    margin: 0.3rem 0;
}
.star-rating .star {
    background: transparent;
    border: none;
    color: #3e322c;
    cursor: pointer;
    padding: 0;
    font-size: 1.8rem;
    margin: 0;
    line-height: 1;
}
.star-rating .star.filled {
    color: var(--accent);
}
.details { list-style: none; padding: 0; margin: 1rem 0; }
.details li { padding: 0.4rem 0; border-bottom: 1px solid #3e322c; }
.bean-photo { max-width: 100%; border-radius: 10px; margin: 1rem 0; }
.inline-form { background: transparent; padding: 0; margin: 0; display: inline; }
.flag { margin-left: 0.3rem; }
.copy-recipe {
    float: right;
    background: transparent;
    border: none;
    color: var(--fg);
    padding: 0 0.3rem;
    font-size: 0.95rem;
    margin: -0.1rem -0.1rem 0 0;
    line-height: 1.4;
    cursor: pointer;
    min-width: 28px;
    min-height: 28px;
}
.copy-recipe.copied { color: var(--ok); }
.day-header {
    font-size: 0.8rem;
    color: var(--accent);
    margin: 1.2rem 0 0.2rem;
    text-transform: uppercase;
}
.hist-item[data-edit] { cursor: pointer; }
.hist-note {
    font-size: 0.85rem;
    color: #a89f99;
    font-style: italic;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.hist-taste { color: var(--accent); }
.star-static { color: var(--accent); font-size: 1rem; letter-spacing: 1px; }
.load-more { display: block; margin: 1rem auto; }
