:root {
    --primary-color: #5c4bdb;
    --primary-gradient: linear-gradient(135deg, #6b5ced 0%, #4633d9 100%);
    --bg-color: #f7f8fa;
    --card-bg: #ffffff;
    --text-main: #1d1d1f;
    --text-muted: #86868b;
    --border-color: #e5e5ea;
    --danger-color: #d93025;
    --success-color: #188038;
    --radius-lg: 20px;
    --radius-md: 12px;
    --radius-sm: 8px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Noto Sans KR', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    display: flex;
    justify-content: center;
    padding: 2rem;
    min-height: 100vh;
}

.app-container {
    width: 100%;
    max-width: 500px;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* Tabs */
.tabs-container {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.tab-btn {
    padding: 0.75rem 1.25rem;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    background-color: transparent;
    color: var(--text-muted);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.tab-btn:hover {
    color: var(--text-main);
}

.tab-btn.active {
    border-color: var(--text-main);
    color: var(--text-main);
    background-color: transparent;
    box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}

/* Cards */
.card {
    background-color: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.04);
}

/* Typography & Inputs */
.section-label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.input-section {
    margin-bottom: 2rem;
}

.input-wrapper {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 0.5rem;
    transition: border-color 0.2s;
}

.input-wrapper:focus-within {
    border-color: var(--primary-color);
}

#inputValue {
    border: none;
    outline: none;
    font-size: 3rem;
    font-weight: 400;
    color: var(--text-main);
    width: 80%;
    background: transparent;
}

.unit-label {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-muted);
}

/* Unit Selection */
.unit-selection {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 2rem;
}

.select-group {
    flex: 1;
}

.custom-select {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-family: inherit;
    color: var(--text-main);
    appearance: none;
    background: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%2386868b%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E") no-repeat right 1rem top 50%;
    background-size: 0.65rem auto;
    background-color: var(--bg-color);
    cursor: pointer;
}

.swap-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background-color: #eeeafc;
    color: var(--primary-color);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    margin-top: 1.5rem;
    transition: transform 0.2s;
}

.swap-btn:hover {
    transform: rotate(180deg);
}

/* Result Box */
.result-section {
    background: var(--primary-gradient);
    border-radius: var(--radius-lg);
    padding: 1.5rem 2rem;
    color: white;
    position: relative;
    overflow: hidden;
    min-height: 140px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    z-index: 2;
}

.result-label {
    font-size: 0.85rem;
    opacity: 0.9;
}

.copy-btn {
    background: transparent;
    border: 1px solid rgba(255,255,255,0.3);
    color: white;
    padding: 0.4rem 0.8rem;
    border-radius: 20px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.copy-btn:hover {
    background: rgba(255,255,255,0.1);
}

.result-value-wrapper {
    position: relative;
    z-index: 2;
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
}

.result-number {
    font-size: 2.8rem;
    font-weight: 500;
}

.result-unit {
    font-size: 1.2rem;
    opacity: 0.9;
}

.bg-icon {
    position: absolute;
    right: 1rem;
    bottom: -1rem;
    font-size: 8rem;
    opacity: 0.1;
    z-index: 1;
    transform: rotate(-15deg);
}

/* Calibration Card Specifics */
.calibration-header {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

@media (min-width: 480px) {
    .calibration-header {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }
}

.cal-title-section {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.cal-title {
    font-size: 1.1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
}

.basis-selection {
    display: flex;
    gap: 1rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.basis-radio {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    cursor: pointer;
    white-space: nowrap;
}

.basis-radio input[type="radio"] {
    accent-color: var(--primary-color);
}

.tolerance-buttons {
    display: flex;
    flex-wrap: wrap;
    background-color: var(--bg-color);
    border-radius: var(--radius-md);
    padding: 0.25rem;
    gap: 0.25rem;
}

.tol-btn {
    flex: 1;
    min-width: max-content;
    white-space: nowrap;
    border: none;
    background: transparent;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.tol-btn.active {
    background: white;
    color: var(--text-main);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.custom-tol-wrapper {
    display: flex;
    align-items: center;
}

.custom-tol-input {
    width: 60px;
    padding: 0.4rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    text-align: center;
    margin-left: 0.5rem;
    font-size: 0.9rem;
}

.hidden {
    display: none !important;
}

/* Ruler Visualizer */
.ruler-settings-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
    padding: 0.5rem 0;
    border-top: 1px dashed var(--border-color);
    border-bottom: 1px dashed var(--border-color);
}

.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.switch input { 
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
}

input:checked + .slider {
    background-color: var(--primary-color);
}

input:checked + .slider:before {
    transform: translateX(20px);
}

.slider.round {
    border-radius: 24px;
}

.slider.round:before {
    border-radius: 50%;
}

.toggle-label {
    font-weight: 500;
    font-size: 0.9rem;
    color: var(--text-main);
}

.ruler-settings-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1.5rem;
    padding: 1rem;
    background-color: var(--bg-color);
    border-radius: var(--radius-sm);
}

@media (min-width: 480px) {
    .ruler-settings-container {
        flex-direction: row;
        align-items: flex-end;
    }
}

.setting-group {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    flex: 1;
}

.setting-label {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.setting-group input {
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
}

.setting-info {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--primary-color);
    margin-top: 0.5rem;
}

.ruler-container {
    width: 100%;
    margin-top: 1rem;
    padding: 0.5rem 0;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.ruler-canvas {
    width: 100%;
    max-width: 400px;
    height: 60px;
}

.ruler-text {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.3rem;
}

/* Table */
.table-container {
    width: 100%;
}

.calibration-table {
    width: 100%;
    border-collapse: collapse;
    text-align: center;
}

.calibration-table th {
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.85rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.calibration-table td {
    padding: 1.25rem 0;
    vertical-align: middle;
}

.cal-percent-badge {
    background-color: var(--bg-color);
    padding: 0.3rem 0.6rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.85rem;
}

.target-val {
    font-weight: 600;
    font-size: 1.1rem;
    display: flex;
    flex-direction: column;
}

.target-unit {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 400;
    margin-top: 2px;
}

.min-val {
    color: var(--danger-color);
    font-weight: 600;
    font-size: 1.1rem;
}

.max-val {
    color: var(--success-color);
    font-weight: 600;
    font-size: 1.1rem;
}